I have a XML that looks like this (arbitrary XML input)
<NodeLevel1>
<NodeLevel2>
<NodeLevel3>
Sample text 1
</NodeLevel3>
</NodeLevel2>
<NodeLevel2>
.
.
.
... <NodeLevelN>
Some deep thought
</NodeLevelN>
</NodeLevel2>
<NodeLevel2>
Sample text 2
</NodeLevel2>
Sample text 3
</NodeLevel1>
What I would like to have after XSLT transformation is 4 new XMLs containing just a single text node like the following 4 XMLs:
1.
<NodeLevel1>
<NodeLevel2>
<NodeLevel3>
Sample text 1
</NodeLevel3>
</NodeLevel2>
</NodeLevel1>
2.
<NodeLevel1>
<NodeLevel2>
.
.
.
... <NodeLevelN>
Some deep thought
</NodeLevelN>
</NodeLevel2>
</NodeLevel1>
3.
<NodeLevel1>
<NodeLevel2>
Sample text 2
</NodeLevel2>
</NodeLevel1>
4.
<NodeLevel1>
Sample text 3
</NodeLevel1>
What is the best way to do that? I’m using C++ (I can use libxml2 and libxslt)
Thanks!
I would use XSLT 2.0 with
xsl:result-documentor in your case with libxslt you can also use theexsl:documentextension element:Thinking about the problem a bit more I have improved the stylesheet to work with any kind of root element:
[edit]
If you want to use an XSLT 2.0 processor like Saxon or AltovaXML or XmlPrime here is an XSLT 2.0 stylesheet: