How to check for string equality case insensitive in xsl
36,592
Solution 1
In the same way:
<xsl:if test="translate(DB/@dbtype, $smallcase, $uppercase) = 'ORACLE'">
Solution 2
Well if you're using XSLT 2.0+ then you can use
http://saxonica.com/documentation/functions/intro/lower-case.xml
i.e.
<xsl:if test="lower-case(product/@name)='oracle'">
something
</xsl:if>
Solution 3
<xsl:if test="translate(product/@name, $smallcase, $uppercase) = translate('Oracle', $smallcase, $uppercase)">
stuff
</xsl:if>
Author by
AabinGunz
Quiet and fun loving, here to learn and share. :) SOreadytohelp Got to share some amazing things. Thanks SO.
Updated on November 17, 2020Comments
-
AabinGunz over 3 years
I have a requirement where I need to check
DB/@dbtype
== 'oracle' (case insensitive). How can I do that? Here is my code<xsl:choose> <xsl:when test="DB/@dbtype"> <p> <dd> <table border="1"> <tbody> <tr> <th>Name</th> <th>Value</th> </tr> <xsl:if test="DB/@dbtype='ORACLE'"> <xsl:for-each select="DB/oracle_props"> <tr> <td valign="top" ><xsl:value-of select="@name"/></td> <td valign="top" ><xsl:value-of select="@value"/></td> </tr> </xsl:for-each> </xsl:if> </tbody> </table> </dd> </p> </xsl:when> <xsl:otherwise> <xsl:value-of select="DB"/> </xsl:otherwise> </xsl:choose>
I thought of converting it into all lowercase/uppercase and then check accordingly, so I used below
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" /> <xsl:value-of select="translate(product/@name, $smallcase, $uppercase)"/> <!--It display in lower case, but how to use this in checking for equality?-->
Please help me out, how to compare String (case insensitive way)