Forum Moderators: coopster & phranque

Message Too Old, No Replies

XML string in an XML node

can I convert it to true XML for an XSL template?

         

joshie76

8:30 am on May 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a bit of a funny one...

We have, for example, the following XML (muchos simplified)

<nodes>
<node>
&lt;childnode&gt;value&lt;/childnode&gt;
<node>
<nodes>

This is a little unfortunate but unavoidable as the data is a string and the xml object builder can't tell the difference between a normal string and one that should be real XML. Only the XSLT knows this (long story).

What I need to do is parse this in XSLT as normal and access the XML and it's values, children, attributes etc stored in the string? For example the Xpath might read "/nodes/node/childnode" I've tried putting it in variables with and without output-escaping disabled and so on without success. Anybody know of a way to do this?

We're using MSXML3. Any help would be greatly appreciated.

korkus2000

2:03 pm on May 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think I completely understand your question. Is the problem you are having, getting the < and > to populate in html and not xml?

Have you tried an <!ENTITY> reference? I am not sure what the character code is for < >.

I have to use the <!ENTITY> reference for nbsp; in my xslt.

joshie76

2:13 pm on May 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks korkus

The &lt; is a result of encoding that happens when we put a string from a DB into an XML node. We can't do much about this at present.

I need to convert the string into XML inside the XSLT that the same XSLT can then parse in the same go... example of what I thought might work:

XML 

<nodes>
<node>
&lt;childnode&gt;value&lt;/childnode&gt;
</node>
</nodes>

XLST

<xsl:variable name="myStringXML">
<xsl:value-of select="/nodes/node"/>
</xsl:variable>

<xsl:for-each select="$myStringXML/childnode">
<xsl:value-of select="."/>
</xsl:for-each>

It didn't - even thought the

<xsl:value-of select="/nodes/node"/>
returns the value without the &lt;s etc it's still a string. What I need is somekind of xml() function that turns a string into a real nodeset.

PS. If you want to avoid using ENTITY just for &nbsp; you can use &#160; instead.