根据XSLT中变量中提供的条件迭代For-each循环



我希望for-each循环在定义的变量中提供的条件下工作。

如果Record_Counter的值为7,那么for_each应该迭代7次。

注意:我已经创建了变量Counter来存储Record_Counter的值。

请找到我尝试过的XSLT代码,但它没有给我想要的结果。

<xsl:variable name= "Counter" select="Element[1]/@Record_Counter" />
<xsl:for-each select="$Counter">
<itemGroup ref="ValTechnique">
<reportItem key="yes">
<itemValue>
<xsl:value-of select="@Reporting"/>
</itemValue>
</reportItem>
<reportItem>
<itemValue>
<xsl:value-of select="@Valuation"/>
</itemValue>
</reportItem>
</itemGroup>
</xsl:for-each>

在XSLT 2及以后的版本中,您当然可以使用1 to $var表达式,例如<xsl:for-each select="1 to xs:integer($Counter)">,但在for-each中,上下文项是当前处理的整数值,因此任何尝试使用例如<xsl:value-of select="@Reporting"/>选择节点都将无效,您需要将例如<xsl:variable name="context-node" select="."/>放在for-each之前,然后在for-each中使用例如<xsl:value-of select="$context-node/@Reporting"/>

这可能还不够,因为你不太可能想要输出相同的东西$Counter次,但你还没有显示你的输入和想要的输出,所以我不能告诉你需要/想要的其他更改。