Replacing '&gt;' with '<' using XSLT

Hi,

I am trying to format some fairly simple data into HTML using an XSLT stylesheet. One of the fields in the XML data actually contains HTML syntax, but every < and > is converted into an &gt; and &lt;. I have found examples of how to replace text using simple template with a couple of parameters. This works quite well for simple text replacements. However, I run into a problem when I try and replace an '&gt;' with a '>'.

The problem is that if I literally write '&gt;' as the replace string, it really does just put '&gt;' in the output. However, if I enter '>' an the replace string, it seems to get escaped somewhere along the way and comes out as '&gt;' in the output (not what I want).

So, my question is: How can I replace every '&gt;' in some XML data into a real '>' using an XSLT stylesheet?

Thanks in advance,
Robert.

---

Below is my current stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="data/row">
      
      <xsl:variable name="gtsrc">&gt;</xsl:variable>
      <xsl:variable name="gtdest">></xsl:variable>
      
      <html>
            
            <h1><xsl:value-of select="$gtsrc"/></h1>
            
            <xsl:for-each select="field">
                  <p>
                        <xsl:call-template name="replace-string">
                              <xsl:with-param name="text" select="."/>
                              <xsl:with-param name="replace" select="$gtsrc"/>
                              <xsl:with-param name="with" select="$gtdest"/>
                        </xsl:call-template>
                  </p>
            </xsl:for-each>
            
      </html>
      
</xsl:template>
<xsl:template name="replace-string">
      
      <xsl:param name="text"/>
      <xsl:param name="replace"/>
      <xsl:param name="with"/>
      
      <xsl:choose>
            <xsl:when test="contains($text,$replace)">
                  <xsl:value-of select="substring-before($text,$replace)"/>
                  <xsl:value-of select="$with"/>
                  <xsl:call-template name="replace-string">
                        <xsl:with-param name="text" select="substring-after($text,$replace)"/>
                        <xsl:with-param name="replace" select="$replace"/>
                        <xsl:with-param name="with" select="$with"/>
                  </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                  <xsl:value-of select="$text"/>
            </xsl:otherwise>
      </xsl:choose>
      
</xsl:template>
</xsl:stylesheet>

Current data:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="printing-test.xsl"?>
<data>
      <row>
            <field>Some simple data</field>
            <field>Here is some &lt;strong&gt;HTML&lt;/strong&gt; data.</field>
      </row>
</data>
headexplodesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
you have to disable the output escaping

           <h1><xsl:value-of select="$gtsrc" disable-output-escaping="yes"/></h1>

don't use it to create non wellformed html though
having to create wellformed output can be a pain in the beginning
but you will soon get the habit right
and escaping all tags and disable the escaping after it is often bad design

the functionality exsists.... but use it with caution

cheers

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gertone (Geert Bormans)Information ArchitectCommented:
here is your new stylesheet

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="data/row">
        <xsl:variable name="gtsrc">&gt;</xsl:variable>
        <xsl:variable name="gtdest">></xsl:variable>
        <html>
            <h1><xsl:value-of select="$gtsrc" disable-output-escaping="yes"/></h1>
           <xsl:for-each select="field">
                <p><xsl:value-of select="." disable-output-escaping="yes"/></p>
            </xsl:for-each>
       </html>
    </xsl:template>
</xsl:stylesheet>
headexplodesAuthor Commented:
thanks for the reply! I will test this when i'm at work next and will most probably accept your answer!
headexplodesAuthor Commented:
Works well. One other thing that was screwing me up was that i was trying to use it with firefox, which seems to ignore the "disable-output-escaping" option. Using Xalan and internet explorer works fine. Damn u firefox! Now I hate both firefox and internet explorer :p.

Anyway, thanks for the help!
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.