[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] replace < and > with < and >
Subject: Re: [xsl] replace < and > with < and > From: Mike Brown <mike@xxxxxxxx> Date: Thu, 19 Sep 2002 19:44:11 -0600 (MDT) |
Ming Yu wrote: > The xml file is returned from a method is in a string format, and the xml > file seems to encode all < and > using < and >. So, what I need to do > is to convert that xml file from a string to a xml nodelist so I can access > all the elements. > > Then, first I need to replace all < and > to < and > and then use a > method I wrote called parseXml which takes a string as parameter and > convert it to a nodelist. > > But I'm stuck on the first step which is converting all < and > to < > and >. > > Here is a sample of my xml file in a STRING: > > <record> > <items> > </items> > </record> I am guessing that despite what you see in the string, your XPath string object actually does contain "<record>", and this only appears as "<record>" when you copy and serialize it using the XML or HTML output method. If so, then you only need to register your parseXml method as an extension function, using the mechanism provided by your XSLT processor vendor, then pass the string to it as-s. If my guess is wrong, then you can use a recursive function to replace the substrings. See http://skew.org/xml/stylesheets/replace/replace.xsl for the SubstringReplace template (this is also in the FAQ but the FAQ site seems to be down today). To replace <, >, and & you'll have to call it 3x like this: <xsl:variable name="betterXml"> <xsl:call-template name="SubstringReplace"> <xsl:with-param name="stringIn"> <xsl:call-template name="SubstringReplace"> <xsl:with-param name="stringIn"> <xsl:call-template name="SubstringReplace"> <xsl:with-param name="stringIn"> <xsl:call-template name="SubstringReplace"> <xsl:with-param name="stringIn" select="$theXml"/> <xsl:with-param name="substringIn" select="'&lt;'"/> <xsl:with-param name="substringOut" select="'<'"/> </xsl:call-template> </xsl:with-param> <xsl:with-param name="substringIn" select="'&gt;'"/> <xsl:with-param name="substringOut" select="'>'"/> </xsl:call-template> </xsl:with-param> <xsl:with-param name="substringIn" select="'&amp;'"/> <xsl:with-param name="substringOut" select="'&'"/> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:variable> Then pass string($betterXml) to your extension function. - Mike ____________________________________________________________________________ mike j. brown | xml/xslt: http://skew.org/xml/ denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] replace < and > with < , Ming Yu | Thread | Re: [xsl] replace < and > wit, Ming Yu |
Re: [xsl] merging with document(), Jeff Shevlen | Date | Re: [xsl] Problem using MSXML, Mike Brown |
Month |