I cannot have nested intervals, so I need to flatten them and combine their class attributes so that I can keep track of which classes are parents.
Here's a simplified entry :
<body> <h1 class="section">Title</h1> <p class="main"> ZZZ <span class="a"> AAA <span class="b"> BBB <span class="c"> CCC <preserveMe> eeee </preserveMe> </span> bbb <preserveMe> eeee </preserveMe> </span> aaa </span> </p> </body>
Here is the desired conclusion
<body> <h1 class="section">Title</h1> <p class="main"> ZZZ <span class="a"> AAA </span> <span class="ab"> BBB </span> <span class="abc"> CCC <preserveMe> eeee </preserveMe> </span> <span class="ab"> bbb <preserveMe> eeee </preserveMe> </span> <span class="a"> aaa </span> </p> </body>
Here is the closest I came (I'm really new to this, so even during that time a lot of time has passed ...)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <p> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match="*/span"> <span class='{concat(../../@class,../@class,@class)}'> <xsl:value-of select='.'/> </span> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet>
You can see the result of my unsuccessful attempt and how far this is from what I really wanted if you ran it yourself. Ideally, I would like the decision to take an arbitrary number of nested levels and also be able to handle interrupted nests (span, span, notSpan, span ...).
edit: I added tags inside the nested structure per request by the commentators below. In addition, I use XSLT v1.0, but if necessary, I could use other versions.
edit 2: I realized that my example was too strong compared to what I really needed to convert. Namely, I cannot lose classes from other tags; only gaps can be combined.