Xml 如何在XSLT中创建增加1个foreach循环的计数器,我有嵌套的foreach循环

Xml 如何在XSLT中创建增加1个foreach循环的计数器,我有嵌套的foreach循环,xml,xslt,Xml,Xslt,如何在XSLT中创建增加1个foreach循环的计数器,我在foreach循环中有一个foreach循环,我已经编写了它,但是一旦父foreach循环开始进行下一次迭代,计数器就被设置为零,然后尝试使用xsl:number。例如: XML <xsl:template match="Quote"> <Quote> <xsl:for-each select="Configuration"> <ConfigI

如何在XSLT中创建增加1个foreach循环的计数器,我在foreach循环中有一个foreach循环,我已经编写了它,但是一旦父foreach循环开始进行下一次迭代,计数器就被设置为零,然后尝试使用
xsl:number
。例如:

XML

<xsl:template match="Quote">
<Quote>    

        <xsl:for-each select="Configuration"> 
            <ConfigItem>
                <xsl:variable name="GeneratedStructure">
                <xsl:variable name="ConfigurationPos" select="position()+10"/> 
                <configurationPostion><xsl:value-of select = "$ConfigurationPos" /> </configurationPostion> 
                <!--  <VariableValue><xsl:value-of select="$ConfigurationPos"/></VariableValue>-->
                <Vendor><xsl:value-of select="Vendor" /></Vendor>
                <PriceListID><xsl:value-of select="PriceListID" /></PriceListID>
                <Source><xsl:value-of select="Source" /></Source>
                <xsl:for-each select="ProductLineItem">
                    <ProductLineItem>
                        <xsl:variable name="ProductPos" select="$ConfigurationPos+(position()*10)"/>
                        <ProductPostionNumber><xsl:value-of select = "$ProductPos" /></ProductPostionNumber>
                    </ProductLineItem>   
                </xsl:for-each>
                </xsl:variable>  
                <xsl:variable name="SubtotalPos" select="max($GeneratedStructure/ProductLineItem/ProductPostionNumber)"/>
                <xsl:copy-of select="$GeneratedStructure"/> 
                <xsl:variable name="max">
                    <xsl:for-each select="$GeneratedStructure/ProductLineItem/ProductPostionNumber">
                        <xsl:sort select="." data-type="number" order="descending"/>

                    </xsl:for-each>
                </xsl:variable>
                <subMax><xsl:value-of select = "number($max)+10" /></subMax>
            </ConfigItem>
        </xsl:for-each>  
</Quote>
</xsl:template>

12333dddd
1.0.1
2.0.1
12ss333dddd
5165550509
XSLT1.0

<Quote>
   <Configuration>
      <RowID>12333dddd</RowID>
      <ProductLineItem>
         <LineNumber>1.0.1</LineNumber>
      </ProductLineItem>
      <ProductLineItem>
         <LineNumber>2.0.1</LineNumber>
      </ProductLineItem>
   </Configuration>
   <Configuration>
      <RowID>12ss333dddd</RowID>
      <ProductLineItem>
         <LineId>5165550509</LineId>
      </ProductLineItem>
   </Configuration>
</Quote>

结果

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="Quote">
    <Quote>    
        <xsl:for-each select="Configuration"> 
            <ConfigItem>
                <configurationPostion>
                    <xsl:number count="Configuration | ProductLineItem" level="any"/>
                </configurationPostion>
                <xsl:for-each select="ProductLineItem">
                    <ProductPostionNumber>
                        <xsl:number count="Configuration | ProductLineItem" level="any"/>
                    </ProductPostionNumber>
                </xsl:for-each>
            </ConfigItem>
        </xsl:for-each>  
    </Quote>
</xsl:template>

</xsl:stylesheet>

1.
2.
3.
4.
5.

xsl:for-each
不是一个循环。通常可以使用“position()”函数为正在处理的节点编制索引。请在问题中添加显示输入和预期结果。12333dddd 1.0.1 2.0.1 12ss333dddd 5165550509添加了示例XML文件请不要在注释中发布代码。编辑您的问题并在此处添加代码。并给出了预期的结果。1 2 3 5 6
<?xml version="1.0" encoding="utf-16"?>
<Quote>
  <ConfigItem>
    <configurationPostion>1</configurationPostion>
    <ProductPostionNumber>2</ProductPostionNumber>
    <ProductPostionNumber>3</ProductPostionNumber>
  </ConfigItem>
  <ConfigItem>
    <configurationPostion>4</configurationPostion>
    <ProductPostionNumber>5</ProductPostionNumber>
  </ConfigItem>
</Quote>