IBM Support

How to check if an element has an apostrophe in the data?

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, &quot;'&quot;) = 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>

[{"Product":{"code":"SSGR73","label":"IBM Cast Iron Cloud Integration"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Studio","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"5.0.1.7;6.0.0.3;6.1.0.6","Edition":"Virtual;Physical;Cloud","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21498623