davidlars99
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-m icrosoft-c om: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,'{$lookupf ield}')">< xslt:value -of select="$lookupfield"/></t d>
</xslt:otherwise>
</xslt:choose>
</xslt:otherwise>
</xslt:choose>
</tr>
</xslt:template>
</xslt:stylesheet>
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-m
<xslt:output media-type="text/html" encoding="UTF-8"/>
<xslt:output method="html"/>
<xslt:output method="xml" omit-xml-declaration="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:when>
<xslt:otherwise>
<xslt:choose>
<xslt:when test="web_name">
<td onmouseover="a(this)" onmouseout="b(this)" onclick="c(this,'{$webname
</xslt:when>
<xslt:otherwise>
<td onmouseover="a(this)" onmouseout="b(this)" onclick="c(this,'{$lookupf
</xslt:otherwise>
</xslt:choose>
</xslt:otherwise>
</xslt:choose>
</tr>
</xslt:template>
</xslt:stylesheet>
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>'</x sl:text></ xsl:param>
<xsl:template match="/">
<xsl:call-template name="replaceApos">
<xsl:with-param name="strRep" select="NewDataSet/Table/w eb_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($str Rep, $apos)">
<xsl:call-template name="replaceApos">
<xsl:with-param name="strRep" select="substring-after($s trRep, $apos)"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise><xsl:value- of select="$strRep"/></xsl:ot herwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
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>'</x
<xsl:template match="/">
<xsl:call-template name="replaceApos">
<xsl:with-param name="strRep" select="NewDataSet/Table/w
</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($
<xsl:text>\'</xsl:text>
<xsl:if test="substring-after($str
<xsl:call-template name="replaceApos">
<xsl:with-param name="strRep" select="substring-after($s
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise><xsl:value-
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
ASKER
Thank you Gertone. Could you please merge your template with my xsl?
ASKER
somehow I can't get it to work... :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
Hello Gertone, it was actually the link vivekthangaswamy provided that made me recommend a split.
well, OK, no prob
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
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
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 :)
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!