XSLT; parse escaped text into node-set and extract subelements
I've been struggling with this problem all day and I'm almost ready to end.
I have an XML file where certain pieces of data are stored as escaped text, but are themselves well-formed XML. I want to convert the entire hierarchy in this text node to node-set and extract the data in it. No combination of variables and functions that I can think of works.
As I expected it will work:
<xsl:variable name="a" select="InnerXML">
<xsl:for-each select="exsl:node-set($a)/*">
'do something
</xsl:for-each>
InnerXML input element contains form text
<root><elementa>text</elementa><elementb><elementc/><elementd>text</elementd></elementb></root>
but it doesn't really matter. I just want to go to the xml like a normal node-set.
Where am I going wrong?
+2
a source to share
2 answers
what i did has a msxsl script in xslt (this is in windows .NET environment):
<msxsl:script implements-prefix="cs" language="C#" >
<![CDATA[
public XPathNodeIterator parse(String strXML)
{
System.IO.StringReader rdr = new System.IO.StringReader(strXML);
XPathDocument doc = new XPathDocument(rdr);
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr;
expr = nav.Compile("/");
XPathNodeIterator iterator = nav.Select(expr);
return iterator;
}
]]>
</msxsl:script>
then you can call it like this:
<xsl:variable name="itemHtml" select="cs:parse(EscapedNode)" />
and this variable now contains xml, you can iterate through
+2
a source to share