2.我试过 contains(translate(."ABCEDF...","abcdef..."),"case-insentive-string")]' 也失败了。
写这个的正确方法是:
/root/book[contains(translate(., $vUpper, $vLower),
translate($vCaseInsentiveString, $vUpper, $vLower)
)
]
其中$vUpper
和$vLower
被定义为(应该被替换)字符串:
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
和
'abcdefghijklmnopqrstuvwxyz'
并且$vCaseInsentiveString
被定义为(应该被替换)特定的不区分大小写的字符串。
例如,给定以下 XML 文档:
<authors>
<author>
<name>Victor Hugo & Co.</name>
<nationality>French</nationality>
</author>
<author period="classical" category="children">
<name>J.K.Rollings</name>
<nationality>British</nationality>
</author>
<author period="classical">
<name>Sophocles</name>
<nationality>Greek</nationality>
</author>
<author>
<name>Leo Tolstoy</name>
<nationality>Russian</nationality>
</author>
<author>
<name>Alexander Pushkin</name>
<nationality>Russian</nationality>
</author>
<author period="classical">
<name>Plato</name>
<nationality>Greek</nationality>
</author>
</authors>
以下 XPath 表达式(用相应的字符串替换变量):
/*/author/name
[contains(translate(., $vUpper, $vLower),
translate('lEo', $vUpper, $vLower)
)
]
选择此元素:
<name>Leo Tolstoy</name>
解释:函数的两个参数contains()
都转换为小写,然后进行比较。