有没有办法找到与某个值的部分匹配的节点。
如果我有以下条件:
<competition id="100" name="Barclays Premier League"/>
<competition id="101" name="CocaCola Championship" />
<competition id="102" name="CocaCola League 1" />给定字符串"Premier“甚至"Prem",我如何匹配正确的节点并获得id 100。
我已经使用for-each和contains来管理这一点,但这非常低效,并且不足以满足我们的需求。
发布于 2008-12-01 11:33:19
字符串处理并不是XSLT的强项,但是有几种选择。
在这种情况下,您可以尝试:
//competition[contains(@name,'Prem')]有关更多选项和详细信息,请参阅here
发布于 2008-12-01 13:31:44
使用:
//competition[contains(@name, 'Prem')]/@id
在其他情况下,诸如:或 (仅限XPath 2.0 )这样的函数可能很有用。
发布于 2008-12-01 12:38:33
还有一个"matches“函数,它使用正则表达式,但它只在XSL2.0中可用。
https://stackoverflow.com/questions/330569
复制相似问题