Firstly I am aware of this question: XSLT: Loop selecting two elements at a time
However I have not found it to work due to the element structure or I just fail with using mod, one of the two.
<input>
<node>
<id>1</id>
<value>3</value>
</node>
<node>
<id>1</id>
<value>3</value>
</node>
<node>
<id>1</id>
<value>3</value>
</node>
<node>
<id>1</id>
<value>3</value>
</node>
<node>
<id>2</id>
<value>4</value>
</node>
<node>
<id>2</id>
<value>4</value>
</node>
<node>
<id>2</id>
<value>4</value>
</node>
<node>
<id>2</id>
<value>4</value>
</node>
</input>
I have the following layout of XML which has the following structure:
– Nodes of the same ID will ALWAYS be grouped together
– There will always be four nodes to one ID
I wish to be able to select the four nodes of one ID at a time and loop through each group of four, so that I can manipulate the data into one output line.
What would be the best way to approach this?
This XSLT:
applied to your Input XML:
gives this grouped Output XML:
The output is grouped by
<id>. Is that what you are looking for? I am not sure. This Muenchian Grouping just simpliefies your structure.