[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: replace &lt; and &gt; with < and >

Subject: Re: replace &lt; and &gt; with < and >
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 19 Sep 2002 19:44:11 -0600 (MDT)
xml lt gt amp
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 &lt; and &gt;. 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 &lt; and &gt; 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 &lt; and &gt; to < 
> and >.
> Here is a sample of my xml file in a STRING:
> &lt;record&gt;
> &lt;items&gt;
> &lt;/items&gt;
> &lt;/record&gt;

I am guessing that despite what you see in the string, your XPath string
object actually does contain "<record>", and this only appears as
"&lt;record&gt;" when you copy and serialize it using the XML or HTML output

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 &lt;, &gt;, and &amp; 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="'&amp;lt;'"/>
                <xsl:with-param name="substringOut" select="'&lt;'"/>
            <xsl:with-param name="substringIn" select="'&amp;gt;'"/>
            <xsl:with-param name="substringOut" select="'&gt;'"/>
        <xsl:with-param name="substringIn" select="'&amp;amp;'"/>
        <xsl:with-param name="substringOut" select="'&amp;'"/>

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


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.