I have an XML structure like the following which is similar to HTML:
<paragraph>
text
<unordered-list>
<list-item>list item</list-item>
</unordered-list>
more text <link url="https://stackoverflow.com">link text</link>
</paragraph>
I want to transform it into HTML using XSLT. The issue is that HTML doesn't allow list elements (<ol>
/<ul>
) within paragraphs (<p>
). Therefore I need to split everything that is outside the lists into a paragraph. I.e. the structure I want to produce should look like this:
<p>
text
</p>
<ul>
<li>list item</li>
</ul>
<p>
more text <a href="https://stackoverflow.com">link text</a>
</p>
My first idea was to loop over all nodes via <xsl:for-each select="./node()">
and put the lists in <ol>
/<ul>
and the rest in <p>
, though that obviously doesn't work because it wraps every node separately.
Searching for answers here I saw XSLT Grouping Siblings, which goes into the same direction, though is meant to split a flat structure into groups. My use case, though, is to "extract" an element and create multiple individual elements from the rest, and by that flatten the structure.
How can that be achieved?