Avatar of davidlars99
davidlars99
Flag for United States of America asked on

replace apostrophe XML

Hi,

How can I replace apostrophe width \'

It has to be replaced with slash followed by apostrophe

Thanks!

<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
      <xslt:output media-type="text/html" encoding="UTF-8"/>
      <xslt:output method="html"/>
      <xslt:output method="xml" omit-xml-declaration="yes" indent="yes"/>        
        <xslt:output method="html"/>
        
      <xslt:template match="/">
            <table cellpadding="0" cellspacing="0">
                  <xslt:apply-templates select="NewDataSet/Table"/>
            </table>
      </xslt:template>
      
      <xslt:template match="NewDataSet/Table">
            <xslt:variable name="webname">
                  <xslt:value-of select="web_name"/>
            </xslt:variable>
            <xslt:variable name="lookupfield">
                  <xslt:value-of select="lookup_field"/>
            </xslt:variable>
            <xslt:variable name="defcoll">
                  <xslt:value-of select="DEFAULT_COLLECTOR"/>
            </xslt:variable>
            <xslt:variable name="empname">
                  <xslt:value-of select="EMPLOYEE_NAME"/>
            </xslt:variable>                                                                                          
            <tr>
                  <xslt:choose>
                        <xslt:when test="DEFAULT_COLLECTOR">
                              <td onmouseover="a(this)" onmouseout="b(this)" onclick="c(this,'{$defcoll}')"><xslt:value-of select="$empname"/></td>
                        </xslt:when>
                        <xslt:otherwise>
                              <xslt:choose>
                                    <xslt:when test="web_name">
                                          <td onmouseover="a(this)" onmouseout="b(this)" onclick="c(this,'{$webname}')"><xslt:value-of select="$webname"/></td>
                                    </xslt:when>
                                    <xslt:otherwise>
                                          <td onmouseover="a(this)" onmouseout="b(this)" onclick="c(this,'{$lookupfield}')"><xslt:value-of select="$lookupfield"/></td>
                                    </xslt:otherwise>                  
                              </xslt:choose>
                        </xslt:otherwise>
                  </xslt:choose>
            </tr>
      </xslt:template>
            
</xslt:stylesheet>
XML

Avatar of undefined
Last Comment
davidlars99

8/22/2022 - Mon
Gertone (Geert Bormans)

Hi davidlars99,

you need to do this in a recursive way
parse through your data and do the replacement one by one

where do you want to replace the ' with \'?

Cheers!
Gertone (Geert Bormans)

davidlars99,

here is a template that replaces the apostrophe
As an example I called it in the element web_name

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="apos"><xsl:text>'</xsl:text></xsl:param>
    <xsl:template match="/">
        <xsl:call-template name="replaceApos">
            <xsl:with-param name="strRep" select="NewDataSet/Table/web_name"/>
        </xsl:call-template>
     </xsl:template>
    <xsl:template name="replaceApos">
        <xsl:param name="strRep"/>
        <xsl:choose>
            <xsl:when test="contains($strRep, $apos)">
                <xsl:value-of select="substring-before($strRep, $apos)"/>
                <xsl:text>\'</xsl:text>
                <xsl:if test="substring-after($strRep, $apos)">
                    <xsl:call-template name="replaceApos">
                        <xsl:with-param name="strRep" select="substring-after($strRep, $apos)"/>
                    </xsl:call-template>
                </xsl:if>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$strRep"/></xsl:otherwise>
        </xsl:choose>
       
    </xsl:template>
 </xsl:stylesheet>
davidlars99

ASKER
Thank you Gertone. Could you please merge your template with my xsl?
Your help has saved me hundreds of hours of internet surfing.
fblack61
davidlars99

ASKER
somehow I can't get it to work...  :(
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Gertone (Geert Bormans)

usually not tricky about points
but I am not sure why vivek should be awarded when he comes home with exactly the same solution three weeks after the facts
sorry for my lack of tolerance

Geert
girionis

Hello Gertone, it was actually the link vivekthangaswamy provided that made me recommend a split.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Gertone (Geert Bormans)

well, OK, no prob
Vivek Thangaswamy

Hi davidlars99

I have given you the sample XSLT code for SEARCH-AND-REPLACE, using that you can replace any character in the xml doc. For more and related topic i have given you the links.

Regards

Vivek
davidlars99

ASKER
I appologize... I was away from the computers for a while. I don't abandon question unless there's a special reason for it  :) you can check my history on that  :)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck