<ROOT>
<A>
<B>TESTING</B>
</A>
</ROOT>
XSL:
<xsl:variable name="nodestring" select="//A"/>
<xsl:value-of select="$nodestring"/>
I am trying to convert XML nodeset to string using XSL. Any thoughts?
<ROOT>
<A>
<B>TESTING</B>
</A>
</ROOT>
XSL:
<xsl:variable name="nodestring" select="//A"/>
<xsl:value-of select="$nodestring"/>
I am trying to convert XML nodeset to string using XSL. Any thoughts?
In XSLT Version 3.0. See http://myxsl.net/xslcompiledtransform/extensions/w3c.xpath.xsl#fn-serialize. This worked for me using SaxonPE.
Search for "XML pretty-printer". Or just have a look at the XSLT code of my XPath Visualizer (though it produces XML representation to be displayed in a browser, but you'll get the idea).
My solution is for Saxon HE, and have this advantages:
I've tried successfully with Saxon HE 9.5.X.
It is about registering a custom extension function with these contents:
You can use this function as follows:
The inverse process is documented here.
Updated based on comments..
OK I've never done exactly what you need before, so take this with that grain of salt (I'm winging it). Basically you need to be very concerned about 2 things: characters that require escaping and white space. In this case, the string that empo gave you in the comments above is more what you're after. Below is one way that you can make your XSL output that:
You still need to be concerned with other characters that require escaping like " ' & I believe you can use translate or replace for those
Based on @jelovirt solution, here is a more complete piece of code:
My solution: