XPath查询以获取包含字符串前缀的节点
如何获取包含作为搜索字符串前缀的节点的记录 XML如下所示:XPath查询以获取包含字符串前缀的节点,xpath,Xpath,如何获取包含作为搜索字符串前缀的节点的记录 XML如下所示: <records> <record> <name>foo</name> <prefix>abc</prefix> </record> <record> <name>bar</name> <prefix>def</prefix> </reco
<records>
<record>
<name>foo</name>
<prefix>abc</prefix>
</record>
<record>
<name>bar</name>
<prefix>def</prefix>
</record>
<record>
<name>bar</name>
<prefix>abc.123</prefix>
</record>
</records>
福
abc
酒吧
def
酒吧
abc.123
因此,如果我有字符串“abc.123.xyz”,我将获取第一条和第三条记录
大致翻译为“/records/record[前缀[包含在?('abc.123.xyz')]””
我看到的任何XPath函数都是以另一种方式工作的(从开始,包含),即指定子字符串而不是包含子字符串的节点。这与示例中的记录节点相匹配:
<xsl:template match="/">
<xsl:apply-templates select="/records/record[starts-with(./prefix, substring-before('abc.123.xyz','.'))]"/>
</xsl:template>
谢谢。这使我想到了我的答案。“/records/record[以('abc.123.xyz',./前缀)开头]