0

I want my for-each loop to work on the condition provide in the variable defined.

If Record_Counter has value 7 in it, then for_each should iterate for 7 times.

Note: I have created the variable Counter to store Record_Counter value.

Please find XSLT code which I tried but it is not giving me desired result.

    <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>

1 Answers1

2

In XSLT 2 and later you can certainly use a 1 to $var expression e.g. <xsl:for-each select="1 to xs:integer($Counter)"> but that way inside of the for-each the context item is the currently processed integer value so any attempt to select nodes with e.g. <xsl:value-of select="@Reporting"/> will not work, you would need to put e.g. <xsl:variable name="context-node" select="."/> before the for-each and then use e.g. <xsl:value-of select="$context-node/@Reporting"/> inside the for-each.

That might still not suffice as it is unlikely you want to output the same stuff $Counter times but you haven't show your input and wanted output so I can't tell what other changes you need/want.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110