<fo:flow flow-name="xsl-region-body">
<xsl:variable name="headerCount">
<xsl:value-of select="count(xPath/To/My/Item)"/>
</xsl:variable>
<xsl:variable name="count" as="xs:integer" select="1"/>
<fo:block>
<xsl:for-each select="xPath/To/My/Item">
<xsl:if test="position() <= $headerCount">
<xsl:value-of select="ItemVal"/>
</xsl:if>
</xsl:for-each>
</fo:block>
</fo:flow>
想要有一个循环计数器似乎是相当程序化的想法;没有必要,您可以处理您选择的序列(XSLT 2/3)或节点集(XSLT 1),只需一个 for-each 或 apply-templates 例如
<xsl:for-each select="xPath/To/My/Item[position() <= count(xPath/To/My/HeaderItem)]">
.
如果您想将序列或节点集的计数存储在变量中,那当然是可能的,但请注意,使用
<xsl:variable name="headerCount" select="count(xPath/To/My/Item)"/>
比嵌套xsl:variable/xsl:value-of
更自然和高效。