I wanted to use xsl:variable and loop based on it's count, but I am not sure if its possible in Xslt. for example if I have a variable name count
<xsl:variable name="count" as="xs:integer" select="4"/>
Can I make use of variable, in below form!!!
<xsl:if test="some condition"/>
loop from 0 to $count
...do something here
end loop
</xsl:if>
Is it possible?
My Input XML:
<Root>
<Element>
<Value>1</Value>
<Value>2</Value>
</Element>
<Element>
<Value>1</Value>
<Value>2</Value>
<Value>3</Value>
<Value>4</Value>
</Element>
<Element>
<Value>1</Value>
</Element>
</Root>
Expected output in flat file is (with line-breaks):
1,2,,
1,2,3,4
1,,,
Any help appreciated. Thanks Mh.
Using XSLT 2.0 a solution could be:
Note: you can also use an if statement instead of the concat function.
Just for completeness, a solution written using XSLT 1.0:
The example "loop" in:
http://www.w3schools.com/xsl/xsl_for_each.asp
you can "match" to each "element" without having to "for-each"
Yes, this is possible in XSLT 2.0 (which, from the
as="xs:integer"
in your example, I assume you're using). The following transform will produce your expected output from your example input: