XSLT/XPath : No upper-case function in MSXML 4.0?

醉酒当歌 提交于 2019-11-30 18:02:13

问题


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:


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')"/>



回答2:


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)



来源:https://stackoverflow.com/questions/1226263/xslt-xpath-no-upper-case-function-in-msxml-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!