How to pass variables between two templates in XSLT.
I cannot use global variable because value of variable is dependent on current node under evaluation.
Say I have XSLT of sort:
<xsl:template match="product">
<xsl:variable name="pr-pos" select="count(./preceding-sibling::product)+1"/>
..
..
..
<xsl:apply-templates select="countries/country"/>
</xsl:template>
<xsl:template match="countries/country">
<tr id="country-id">
<td><a href="#" class="action" id="{concat('a-',$pr-pos)}">+</a></td>
..
..
This gives error as $pr-pos is not accessible in second template.
How do I pass variable pr-pos' value to other template? How can I do this?
<xsl:template match="product">
<xsl:variable name="pr-pos" select="count(./preceding-sibling::product)+1"/>
..
..
..
<xsl:apply-templates select="countries/country">
<xsl:with-param name="pr-pos" select="$pr-pos" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="countries/country">
<xsl:param name="pr-pos" />
<tr id="country-id">
<td><a href="#" class="action" id="{concat('a-',$pr-pos)}">+</a></td>
..
..
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