Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for string equality case insensitive in xsl

Tags:

xml

xslt

xpath

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)

like image 655
AabinGunz Avatar asked Jan 20 '12 11:01

AabinGunz


2 Answers

In the same way:

<xsl:if test="translate(DB/@dbtype, $smallcase, $uppercase) = 'ORACLE'">
like image 135
Kirill Polishchuk Avatar answered Sep 16 '22 21:09

Kirill Polishchuk


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>
like image 23
Dino Fancellu Avatar answered Sep 19 '22 21:09

Dino Fancellu