This is what I'm trying to do in XSL:
<xsl:apply-templates select="document('a.xml')//row"/>
<xsl:apply-templates select="document('b.xml')//row"/>
<xsl:template match="row">
<!-- for document a.xml -->
</xsl:template>
<xsl:template match="row">
<!-- for document b.xml -->
</xsl:template>
Doesn't work as is now, for obvious reasons. How can I differentiate these two templates? Document a.xml and b.xml are absolutely identical in terms of XML structure.
Use the mode attribute.
<xsl:apply-templates select="document('a.xml')//row" mode="a"/>
<xsl:apply-templates select="document('b.xml')//row" mode="b"/>
<xsl:template match="row" mode="a">
<!-- for document a.xml -->
</xsl:template>
<xsl:template match="row" mode="b">
<!-- for document b.xml -->
</xsl:template>
You can use the mode attribute as suggested, though this does mean that the decision is made partly at the xsl:apply-templates level and partly by the template rule itself. If you want the control to be purely in the template rule, you could use the match patterns
row[(/) is document('a.xml')]
row[(/) is document('b.xml')]
(If you're still using XSLT 1.0, replace "A is B" by "generate-id(A) = generate-id(B)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With