Francesco Irrera
Francesco Irrera

Reputation: 473

Xslt 1.0 Numeric Variable

Usually the programming languages ​​allow you to declare a variable for example:

Dim test as integer <-- Visual Basic

and subsequently allow to increase the value in a for each cycle.

for test=0 to 3
    print test
next 

Can I create a similar structure in XSLT 1.0?

With 'xsl:variable', I declare a variable, but if I want to increase in a for-each as you do?

Upvotes: 0

Views: 288

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167581

The closest is XSLT 2.0 with

<xsl:for-each select="0 to 3">
  <xsl:value-of select="."/>
</xsl:for-each>

which processes the sequence of integers 0, 1, 2, 3.

As you see, it does not use a variable and increments that, as variables are immutable, you simply bind a value to them once.

With XSLT 1.0 you can process nodes or you can write a recursive, named templates where each recursive call passes on an incremented parameter value. Whether you actually need that depends on your requirements, if you are new to the declarative programming of XSLT then it is best that you define your problem by showing a sample of the XML input and the corresponding output you want to create, explaining how the input is mapped to the output.

Upvotes: 1

Related Questions