XSLT指的是每个模板中模板的当前节点
如何在XSLT指的是每个模板中模板的当前节点,xslt,Xslt,如何在for each循环中引用与模板匹配的当前节点 <xsl:template match="product[@category='foo']"> <count> <xsl:for-each select="preceding::product"> <current> <xsl:value-of select="count(current()/p
for each
循环中引用与模板匹配的当前节点
<xsl:template match="product[@category='foo']">
<count>
<xsl:for-each select="preceding::product">
<current>
<xsl:value-of select="count(current()/preceding::product)"/>
</current>
<context>
<xsl:value-of select="count(./preceding::product)"/>
</context>
</xsl:for-each>
</count>
</xsl:template>
这两个count()
函数返回与
以及current()
相同的结果
是否有一种方法可以引用模板的匹配节点,以便对其前面的所有节点进行计数,从而使
内的count()
函数的结果对于每个步骤都是相同的
谢谢 将当前节点放入变量中
<xsl:template match="product[@category='foo']">
<xsl:variable name="current" select="." />
<count>
<xsl:for-each select="preceding::product">
<current>
<xsl:value-of select="count($current/preceding::product)"/>
</current>
<context>
<xsl:value-of select="count(./preceding::product)"/>
</context>
</xsl:for-each>
</count>
</xsl:template>
<xsl:template match="product[@category='foo']">
<xsl:variable name="count" select="count(preceding::product)" />
<count>
<xsl:for-each select="preceding::product">
<current>
<xsl:value-of select="$count"/>
</current>
<context>
<xsl:value-of select="count(./preceding::product)"/>
</context>
</xsl:for-each>
</count>
</xsl:template>
但在本例中,最好将计数结果放入变量中
将当前节点放入变量
<xsl:template match="product[@category='foo']">
<xsl:variable name="current" select="." />
<count>
<xsl:for-each select="preceding::product">
<current>
<xsl:value-of select="count($current/preceding::product)"/>
</current>
<context>
<xsl:value-of select="count(./preceding::product)"/>
</context>
</xsl:for-each>
</count>
</xsl:template>
<xsl:template match="product[@category='foo']">
<xsl:variable name="count" select="count(preceding::product)" />
<count>
<xsl:for-each select="preceding::product">
<current>
<xsl:value-of select="$count"/>
</current>
<context>
<xsl:value-of select="count(./preceding::product)"/>
</context>
</xsl:for-each>
</count>
</xsl:template>
谢谢!因此,当前和上下文之间的差异只在一个特定的XPath表达式中起作用?请参阅