Reputation:
I have an XSL file that makes use of an XML file. The XSL file needs to display the information found in the XML document twice, but slightly differently each time.
How can I declare different templates that have the same match, but specify which template I want to be called when using <xsl:apply-templates select="...">...</>
Upvotes: 2
Views: 2211
Reputation: 163262
How can I declare different templates that have the same match, but specify which template I want to be called when using ...
Use modes. In the template rule:
<xsl:template match="xyz" mode="mode1"/>
In the apply-templates call:
<xsl:apply-templates select="abc" mode="mode1"/>
When searching for the "best fit" template rule, only template rules in the appropriate mode are considered.
Modes are available in all XSLT versions. In XSLT 3.0 you can declare properties of a mode, for example
<xsl:mode name="mode1" streamable="yes" on-no-match="fail"/>
Upvotes: 2