In the example XSL transformation file below, the "record" and "event" templates are almost identical. They have some distinct text at the top and bottoms of the templates, but there is repeated text in the middle that is identical for the two.
Is there a way that I can put that identical text in another file or (ideally) in another block within this same file, and then add a single-line refence/include into the "record" and "event" templates to refer to that code?
This way, I could have a block of code that is only written once, but gets referred to multiple times. The below is a simplified example. In my real work, the repeated block of code is much larger, and is repeated many more times.
Thank you.
<?xml version="1.0" encoding="UTF-8"?>
<!-- First define the style sheet format to be used -->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude"
exclude-result-prefixes='xsl xi'
type="text/xsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="record"/>
<xsl:apply-templates select="event"/>
</xsl:template>
<xsl:template match="event">
[Event-specific XSL/XML...]<xsl:text>
</xsl:text><Block name="{@name}" mutable="true"><xsl:text>
</xsl:text><XmlElement elementName="action"><xsl:text>
</xsl:text><XmlElement elementName="name"><xsl:text>
</xsl:text><String value="Set"/><xsl:text>
</xsl:text></XmlElement><xsl:comment>End of name</xsl:comment><xsl:text>
</xsl:text><XmlElement elementName="params"><xsl:text>
</xsl:text><Number value="{@id}" size="32" mutable="true"/><xsl:text>
</xsl:text></XmlElement><xsl:comment>End of params</xsl:comment><xsl:text>
</xsl:text></XmlElement><xsl:comment>action</xsl:comment><xsl:text>
</xsl:text></Block><xsl:text>
</xsl:text>[More Event-specific XSL/XML...]<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="record">
[Record-specific XSL/XML...]<xsl:text>
</xsl:text><Block name="{@name}" mutable="true"><xsl:text>
</xsl:text><XmlElement elementName="action"><xsl:text>
</xsl:text><XmlElement elementName="name"><xsl:text>
</xsl:text><String value="Set"/><xsl:text>
</xsl:text></XmlElement><xsl:comment>End of name</xsl:comment><xsl:text>
</xsl:text><XmlElement elementName="params"><xsl:text>
</xsl:text><Number value="{@id}" size="32" mutable="true"/><xsl:text>
</xsl:text></XmlElement><xsl:comment>End of params</xsl:comment><xsl:text>
</xsl:text></XmlElement><xsl:comment>action</xsl:comment><xsl:text>
</xsl:text></Block><xsl:text>
</xsl:text>[More Record-specific XSL/XML...]<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
you can create a new template
<xsl:template name="theCommonPart">
<Block name="{@name}" mutable="true"><xsl:text>
</xsl:text><XmlElement elementName="action"><xsl:text>
</xsl:text><XmlElement elementName="name"><xsl:text>
</xsl:text><String value="Set"/><xsl:text>
</xsl:text></XmlElement><xsl:comment>End of name</xsl:comment><xsl:text>
</xsl:text><XmlElement elementName="params"><xsl:text>
</xsl:text><Number value="{@id}" size="32" mutable="true"/><xsl:text>
</xsl:text></XmlElement><xsl:comment>End of params</xsl:comment><xsl:text>
</xsl:text></XmlElement><xsl:comment>action</xsl:comment><xsl:text>
</xsl:text></Block><xsl:text>
</xsl:text>
</xsl:template>
and call it from your existing templates by replacing this block with
<xsl:call-template name="theCommonPart"/>