remove specail character from xml using xslt

Discussion in 'XML' started by lakshmanavignesh, Nov 2, 2011.

  1. lakshmanavignesh

    lakshmanavignesh

    Joined:
    Nov 2, 2011
    Messages:
    1
    Hi All,

    I have simple doubt in xml - xsl mapping
    I need to remove a special character '&' , ';' from the XML using XSL.
    My input XML will look like:
    <Details>
    <Name>xxx & yyy </Name>
    </Details>
    My output will look like:
    <Person>
    <Name> xxx yyy </Name>
    </Person>
    I am using a xsl where i am trying to convert all the special characters to empty space.
    all other special characters are translted but whenever & come throwing error.
    Could you please guide me how to handle & using xsl.
    Thanks in advance.

    This is my xsl sheet:
    Code:
    <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version="1.0">
    <xsl:eek:utput method="xml" indent="yes" ></xsl:eek:utput>
    <xsl:template name="stripSpecialChars">
    <xsl:param name="string" />
    <xsl:value-of select="translate($string,'()*%$#@!~&lt;&gt;,.?[]=-+/\',' ')"/>
    </xsl:template>
    <xsl:template match="/">
    <xsl:text><![CDATA[<Person>]]></xsl:text>
    <xsl:text><![CDATA[<Name>]]></xsl:text>
    <xsl:call-template name="stripSpecialChars">
    <xsl:with-param name="string" select="/Details/Name"/>
    </xsl:call-template>
    <xsl:text><![CDATA[</Name>]]></xsl:text>
    <xsl:text><![CDATA[</Person>]]></xsl:text>
    </xsl:template>
    </xsl:stylesheet>
    lakshmanavignesh, Nov 2, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon-Pierre  Jarry
    Replies:
    2
    Views:
    2,367
    Henrik
    Aug 10, 2005
  2. Stylus Studio
    Replies:
    0
    Views:
    651
    Stylus Studio
    Aug 3, 2004
  3. daz_oldham

    XSLT to remove HTML from XML

    daz_oldham, Aug 16, 2005, in forum: XML
    Replies:
    0
    Views:
    609
    daz_oldham
    Aug 16, 2005
  4. dar_imiro@hotmail.com
    Replies:
    4
    Views:
    667
    dar_imiro@hotmail.com
    Dec 13, 2005
  5. Daniel Mark
    Replies:
    6
    Views:
    70,740
    Tim Chase
    Sep 28, 2006
Loading...

Share This Page