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

How to Replace Special Characters ?

Subject: How to Replace Special Characters ?
From: "Rohitav Samanta" <rohitav_samanta@xxxxxxxxx>
Date: Thu, 08 Aug 2002 05:27:51 -0700
Hi All,
I want to replace the special characters (e.g double quote right) before tranforming.

My XML looks like
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
<s:Schema id='RowsetSchema'>
	<s:ElementType name='row' content='eltOnly'>
		<s:AttributeType name='Responsibilities' rs:number='14'
			<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='4000'
		<s:extends type='rs:rowbase'/>
		Responsibilities='Assisted Senior Systems Analyst in the design, development, and implementation of an integrated data system for the Texas Department of Health and Human Services.  Participated in liaison and &#x26;#8220;programming&#x26;#8221; &#x22; `&#x26;#8217; &#x27; activities with State officials and private-sector providers to develop policies and data interfaces required to track enrollees&#x26;#8217; health care assessment, enrollment status, third party resources, and provider history.  Responsible for the statistical analyses of State and Federal health care policies to determine their impact on Medicaid recipients and managed care system design.'

To get rid of the special characters I have written the following template.

<xsl:call-template name="transformXMLString">
<xsl:with-param name="StringToTransform">
<xsl:value-of select="//WorkHistory/xml/rs:data/z:row@Responsibilities" disable-output-escaping="yes"/>

	Transform XML to replace special characters
<xsl:template name="transformXMLString">
<!-- import $StringToTransform -->
   <xsl:param name="StringToTransform" />
<!-- string contains quote double left -->
      <xsl:when test="contains($StringToTransform,'&#x26;#8220;')">
        <xsl:value-of select="translate($StringToTransform,'&#x26;#8220;','&quot;')" />
<!-- string contains quote double right -->
      <xsl:when test="contains($StringToTransform,'&#x26;#8221;')">
         <xsl:value-of select="translate($StringToTransform,'&#x26;#8220;','&quot;')" />
<!-- string contains quote left -->
	  <xsl:when test="contains($StringToTransform,'&#x26;#8216;')">
         <xsl:value-of select="translate($StringToTransform,'&#x26;#8216;','&apos;)" />
<!-- string contains quote right -->
      <xsl:when test="contains($StringToTransform,'&#x26;#8217;')">
         <xsl:value-of select="translate($StringToTransform,'&#x26;#8217;','&apos;)" />
<!-- string contains linefeed -->
      <xsl:when test="contains($StringToTransform,'&#10;')">
         <xsl:value-of select="substring-before($StringToTransform,'&#10;')" />
<!-- repeat for the remainder of the original string -->
         <xsl:call-template name="transformXMLString">
            <xsl:with-param name="StringToTransform">
               <xsl:value-of select="substring-after($StringToTransform,'&#10;')" />
<!-- string contains carriage return -->
      <xsl:when test="contains($StringToTransform,'&#13;')">
         <xsl:value-of select="substring-before($StringToTransform,'&#13;')" />
<!-- repeat for the remainder of the original string -->
         <xsl:call-template name="transformXMLString">
            <xsl:with-param name="StringToTransform">
               <xsl:value-of select="substring-after($StringToTransform,'&#13;')" />
<!-- string does not contain any special character, so just output it -->
         <xsl:value-of select="$StringToTransform" />

This template is not very efficient. It still leaves some sepcial characters.
If you have any other template or method which is more efficient  or if you know how to improve my template please let me know.


Win a First Class Trip to Hawaii to Vacation Elvis Style!

 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.