I have an XML file that look like this and I'm trying to wrap "Para_bb" node that are adjacent to each other with a div.
<Para_a></Para_a>
<Para_a></Para_a>
<Para_bb></Para_bb>
<Para_bb></Para_bb>
<Para_bb></Para_bb>
<Para_bb></Para_bb>
<Para_a></Para_a>
<Para_bb></Para_bb>
<Para_bb></Para_bb>
<Para_a></Para_a>
<Para_a></Para_a>
<Para_bb></Para_bb>
How can I make it look like this?
<p></p>
<p></p>
<div class="blackBox">
<Para_bb></Para_bb>
<Para_bb></Para_bb>
<Para_bb></Para_bb>
<Para_bb></Para_bb>
</div>
<p></p>
<div class="blackBox">
<Para_bb></Para_bb>
<Para_bb></Para_bb>
</div>
<p></p>
<p></p>
<div class="blackBox">
<Para_bb></Para_bb>
</div>
You can define a key as follows:
That transforms
into
One way to do this in XSLT 1.0 is to have a template that matches the first occurrence of each Para_bb element in a group
Then you would call a new template, with a mode specified, just on this first element
Then, in the template matching Para_bb with the mode specified, you would copy the element, and select the next sibling, but only if it is another Para_bb
(Where the named template being called is the standard identity template)
Try this XSLT