如何在XSLT中的两个模板之间传递变量.
我不能使用全局变量,因为变量的值取决于评估中的当前节点.
说我有XSLT的排序:
<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>
..
..
Run Code Online (Sandbox Code Playgroud)
这会产生错误,因为在第二个模板中无法访问$ pr-pos.
如何将变量pr-pos'值传递给其他模板?我怎样才能做到这一点?
Don*_*oby 10
<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>
..
..
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8552 次 |
| 最近记录: |