我有以下XML
<Answer>
<Label>FCVCMileage</Label>
<Value>3258</Value>
<Iteration>0</Iteration>
<DataType>NUMBER</DataType>
</Answer>
需要获得里程标签下的价值。但是,“前程万里”的4个字母前缀可以是8个不同前缀中的任意一个。
我知道我可以通过使用xsl测试每个组合来找到值:if或xsl:choose但是有一种更优雅的方式可以像下面的SQL一样工作,也不需要更改代码其他前缀已被添加。
WHERE label LIKE '%Mileage'
NB。只有1个标签元素包含单词Mileage
干杯!
答案 0 :(得分:3)
Answer[contains(Label, 'Mileage')]/Value
答案 1 :(得分:3)
I know I could find the value by testing for every combination using xsl:if or xsl:choose but is there a more elegant way that would work similar to the following SQL and also wouldn't need changes to code being made if other prefixes were added.
WHERE label LIKE '%Mileage'
在XPath 2.0 中有一个标准函数ends-with()
在XPath 1.0中使用:
/*[Label[substring(., string-length(.) - 6) = 'Mileage']]/value
注意强>:
contains(Label, 'Mileage')
不等同于上面的SQL子句。例如,它将选择此节点:
<Label>xxx Mileage yyy</Label>