I have some XML document with <item>
elements, and i'd want to wrap each 3 of them in <div>
If there is less than 3 elements, wrap them too.
<shop>
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
<item></item>
.....
<item></item>
</shop>
So result must be something like this
<div class="line">
<item></item>
<item></item>
<item></item>
</div>
<div class="line">
<item></item>
<item></item>
<item></item>
</div>
....
<div class="line">
<item></item>
<item></item>
</div>
Probably your solution will be very similar to this:
HTML table with alternating row colors via XSL
A much simpler solution:
when applied on the provided XML document:
produces the wanted, correct result:
Update:
The OP has clarified that he needs a transformation that would process the XML document on this page. Everything should be copied as-is with the exception of any group of
<item>
elements that must be grouped by three and each group wrapped into a<div>
.Here is the code for this:
The following stylesheet:
Applied to this input:
Produces:
I haven't tried this, but important is the test in the foreach loop.
count(item) mod 3 = 0
than you can react every third time.