views:

1464

answers:

3

I try to use upper-case() in an XPATH, my parser is MSXML 4.0, and I get :

upper-case is not a valid XSLT or XPath function.

Is it really not implemented ?

+1  A: 

Maybe this can help you:

translate(string, string, string)

The translate function takes a string and, character-by-character, translates characters which match the second string into the corresponding characters in the third string. This is the only way to convert from lower to upper case in XPath. That would look like this (with extra white space added for readability). This code would translate the employee last names to upper case and then select those employees whose last names begin with A.

descendant::employee[
 starts-with(
  translate(@last-name, 
      "abcdefghijklmnopqrstuvwxyz", 
      "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 
  "A"
 ) 
]

If the second string has more characters than the third string, these extra characters will be removed from the first string. If the third string has more characters than the second string, the extra characters are ignored.

(from http://tutorials.beginners.co.uk/professional-visual-basic-6-xml-part-1-using-xml-queries-and-transformations.htm?p=3)

noesgard
+8  A: 

There are no functions in xslt 1.0 to convert to uppercase or lowercase. Instead do the following:

If it is required in a lot of places:

Declare these two xsl variables (this is to make the xslt more readable)

<!-- xsl variables up and lo and translate() are used to change case -->
  <xsl:variable name="up" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  <xsl:variable name="lo" select="'abcdefghijklmnopqrstuvwxyz'"/>

And use them in your translate function to change the case

<xsl:value-of select="translate(@name,$lo,$up)"/>

If you need to use it in just one place, no need to declare variables

<xsl:value-of select="translate(@name,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
Rashmi Pandit
looks quite a lot like my answer even though I did not write the code explicitly
noesgard
@noesgard : In close ties you have to make a choice, it indeed looks like your answer but with better formatting and explicit code... Still I upvoted yours too.
subtenante
I am sorry noesgard, but I started typing the answer when there weren't any posted yet. And I have posted what I have implemented in my xslt.
Rashmi Pandit
Dont have to be sorry, just wondered if I had overlooked something concerning the chosen solution. I haven't - you just described it better and more user friendly.
noesgard
A: 

i had used ur version since XSL 1.0 doesnt support upper-case() ... Thanks a lot Ganesh GOWTHAM

ganesh gowtham