Further suppose that the schema allows section tags to contain any single letter tag a-z. Also any single letter tag a-z may contain any combination of single letter tags a-z. All single letter tags support mixed content as well.
How is it possible using XSLT to do convert the document to one such as the following.
The idea is that whenever a new type attribute is encountered on a tag, we close the close everything up to a certain stopping point such as the child of root in this case, and then we re-open duplicates of everything, and continue on with the processing.
I think it is fairly trivial to write a transform that goes from the latter to the former, but I can think of no way to go from the former to the latter.
Subject:Brain Teaser Author:James Durning Date:05 Sep 2007 12:07 PM Originally Posted: 05 Sep 2007 11:58 AM
To be honest, since this uses xml merely as a linear processing language, I would use a linear programming language to do this. Eg SAX in Java would be a much better tool.
If you're stuck with XSLT, I'm pretty sure you would need the use of node-set variables, which requires common extension functions or XSLT 2.0
Another possible way to do this is to have 26 variables for each of the 26 tags, but the code gets very, very ugly.
The way I could see doing this at the moment would be something like:
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="carry" select="$carry">
</xsl:apply-templates>
General XSLT questions are best asked on the xsl-list run by
Mulberry Technologies. It draws from a much broader pool of
experts as it is not limited to any one product.