xml – 如何在XSLT中的两个模板之间传递变量
发布时间:2020-12-16 05:35:16 所属栏目:百科 来源:网络整理
导读:如何在XSLT中的两个模板之间传递变量. 我不能使用全局变量,因为变量的值取决于评估中的当前节点. 说我有XSLT的排序: xsl:template match="product"xsl:variable name="pr-pos" select="count(./preceding-sibling::product)+1"/......xsl:apply-templates s
如何在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> .. .. 这会产生错误,因为在第二个模板中无法访问$pr-pos. 如何将变量pr-pos’值传递给其他模板?我怎样才能做到这一点? <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> .. .. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |