有没有办法找到一个值匹配的节点.
如果我有以下内容:
<competition id="100" name="Barclays Premier League"/>
<competition id="101" name="CocaCola Championship" />
<competition id="102" name="CocaCola League 1" />
Run Code Online (Sandbox Code Playgroud)
给定字符串"Premier League"或甚至"Prem",我将如何匹配正确的节点并获得id 100.
我已经使用for-each和contains来管理它,但是效率非常低,并且不能满足我们的要求.
ann*_*ata 14
字符串处理不是XSLT令人惊讶的东西,但有一些选项.
在这种情况下,您可以尝试:
//competition[contains(@name,'Prem')]
Run Code Online (Sandbox Code Playgroud)
请看这里了解更多选项和细节
使用:
//competition[contains(@name, 'Prem')]/@id
在其他情况下,诸如:starts-with()或ends-with()(仅限XPath 2.0)可能很有用.