Troubleshooting
Problem
How to check if an element has an apostrophe in the data?
Resolving The Problem
To check if an element has an apostrophe, use either javascript or XSLT. In this example, we have used XSLT to check for an apostrophe for an element.
Below is the XSLT which will check whether an apostrophe is present in an element.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="exslt bpws" version="2.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
xmlns:exslt="http://exslt.org/common"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:variable name="srcDoc1">
<Test xmlns="">
<name xmlns="">n'ame</name>
<value xmlns="">value</value>
</Test>
</xsl:variable>
<xsl:template match="/">
<Result>
<Value>
<xsl:choose>
<xsl:when test="contains($srcDoc1/*:Test/*:name, "'") = true() ">
<!-- true - if there is apostrophe in the name element -->
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- false - if there is no apostrophe in the name element -->
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</Value>
</Result>
</xsl:template>
</xsl:stylesheet>
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21498623