I have an XML of this kind:
<xml>
<node1>1.1</node1>
<node1>1.2</node1>
<node1>1.3</node1>
<node2>2.1</node2>
<node2>2.2</node2>
<node2>2.3</node2>
<node3>3.1</node3>
<node3>3.2</node3>
<node3>3.3</node3>
</xml>
and I want to get the following output:
line: 1.1 + 2.1 + 3.1
line: 1.2 + 2.2 + 3.2
line: 1.3 + 2.3 + 3.3
Is there a way I can iterate over these nodes simultaneously and keep track of my current position in each of three lists or do I have to wrap these items into a bigger block and iterate over blocks?
I’m using XSL 1.0.
As easy as this:
When this transformation is applied on the following XML document (based on the provided one):
the wanted, correct result is produced:
Do note:
In XSLT 1.0 and XSLT 2.0 one can use the FXSL template/function
zip-with3().In XPath 3.0 (XSLT 3.0) there will be a standard function
map-pairs(), but there is nomap-tripples()standard function. One can use this function to produce an intermediate result and then use it again to produce the final result.As noted by Ian Roberts, the presence of
xsl:strip-spacein this solution is important — without it theposition()function produces different results and the transformation doesn’t perform as required.