xslt string compare

String Comparison

1. Case insensitive string compare
2. String comparision in XPath

1.

Case insensitive string compare

David Carlisle

How do I express the following expression in xslt:

if the case-insensitive value of $name == the case-insensitive value of "Joe"

test="translate($name,'JOE','joe')='joe'"

Or more generally, if you are speaking English, you can use

<xsl:variable name="up" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lo" select="'abcdefghijklmnopqrstuvwxyz'"/>


test="translate($name,$up,$lo)='joe'"

For other languages you might have to decide what case-insensitive means, which isn't always easy:-)

Mike Kay adds

<xsl:variable name="uc">ABCDEFG.....</xsl:variable>
<xsl:variable name="lc">abcdefg.....</xsl:variable>

<xsl:if test="translate($name, $lc, $uc) = translate('Joe', $lc, $uc)">

2.

String comparision in XPath

David Carlisle


> "2000-03-30<=@date"

<= only works on numbers.
    

If you know the dates are always in the form yyyy-mm-dd then you can do

"20000330 <=translate(@date,'-','')"

If you want to use more exotic date forms then probably you want to use an extension function to get date handling functions from java.