I have the following input xml and was wondering if XSLT can handle such transformation. If it can, how can it be achieve?
input xml:
<foo><bar><A>xxx</A><B>yyy</B><C>zzz</C><A>aaa</A><B>bbb</B><C>ccc</C> ... .. </bar></foo>
output xml:
<data><A>xxx</A><B>yyy</B><C>zzz</C></data><data><A>aaa</A><B>bbb</B><C>ccc</C></data> ....
There could be more repeating A, B, C nodes in the example above. Since the repetition isn't in a repeating parent node, it's not possible to use for each. I was exploring the option of for-each-group but not sure if that is applicable. Would appreciate any advise.
Jayden Bell
06-Nov-2014Result:
As short explanation - in the template matching "bar" all element-nodes are processed in
By using <xsl:if test="(position()-1) mod(3) = 0"> (which is 0 for the 1st node and for every 3rd node) the template named "grouping" is called to provide generating groups of 3 nodes. This template is called with the parameters position - the position of the current node - and amount - the amount of nodes to be copied in each group.