简体   繁体   中英

XSLT / XML: convert apostrophe to a space

XSLT / XML: convert apostrophe to a space

My XML

<Name>KUEN'S INTERNATIONAL</Name>

USING XSL NEED TO CONVERT TO

<Name>KUENS INTERNATIONAL</Name>

In my xsl I have a template, where I am replacing the some special characters with spaces.

I need to replace ' apostrophe from the string, which throws an error.

I even looked into some of the answers related with the issue, some have tried with version 2.0 but I am working in 1.0

Can you tell me how these special characters works -> <>&apos; How to convert ' apostrophe to space

<xsl:template name="stripSpecialChars">
    <xsl:param name="string" />    
    <xsl:value-of select="translate($string,'()*%$#@!~&lt;&gt;&amp;apos;,.?[]=-+/\',' ')"/> 
</xsl:template> 


<xsl:text><![CDATA[<NAME>]]></xsl:text>                         
   <xsl:call-template name="stripSpecialChars">
        <xsl:with-param name="string" select="/Name"/>
    </xsl:call-template>
<xsl:text><![CDATA[</NAME>]]></xsl:text>

Use another variable for that:

<xsl:template name="stripSpecialChars">
  <xsl:param name="string"/>
  <xsl:variable name="stopset" select='"()*%$#@!~&lt;&gt;&apos;,.?[]=-+/\"'/>
  <xsl:value-of select="translate($string, $stopset, ' ')"/>
</xsl:template>

One line version

<xsl:template name="stripSpecialChars">
  <xsl:param name="string"/>
  <xsl:value-of select='translate($string, "()*%$#@!~&lt;&gt;&apos;,.?[]=-+/\", " ")'/>
</xsl:template>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM