How can I make a XSLT to transform this:
<root>
<element>This
<element>is</element>
</element>
<element>normal!</element>
<element>This</element>
<element>will
<special>break here</special>
<element>and
<element>also
<special>here!</special>
</element>
</element>
</element>
</root>
Into this:
<root>
<content>This is normal! This will</content>
<special>break here</special>
<content>and also</content>
<special>here!</special>
</root>
Considering <special>can appear any number of times and anywhere. I think I need to process the file two times to be able to do that, but I need to do it at once.
EDIT: Just a clarification, it isn’t a simple copy, the content is also transformed from one end to another (that why I thought I need two different transformations).
EDIT2: Here is the algorithm of what I want:
1) Go proccessing all elements until you find some special element, put it all so far inside <content>
2) If the next element is special put it inside <specialContent>
3) If there is something left go to step 1.
EDIT3 I changed my sample xml to make it clearer.
Dimitri answer was very good, but it would break somethings in my XSLT due to generated content and a very deep template hierarchy.
Here is the solution I end up using:
First I do all the normal processing, then I call a post-process:
In the post-process it searches for anything that is not a
divwith WideContent tag in its class attribute and groups the adjacent siblings inside another div, the ones with the WideContent tag are simply copied (but could as well be also group in the same manner).Any suggestions on how to improved that will be gladly taken.