Xpath 对列表中以XML元素中的值表示的值进行计数。
我有这样一些XML:Xpath 对列表中以XML元素中的值表示的值进行计数。,xpath,Xpath,我有这样一些XML: <lines> <line> <entity>H</entity> <account>1002</account> <taxcode>ESCR04</taxcode> </line> <line> <entity>H</entity> <account>1003<
<lines>
<line>
<entity>H</entity>
<account>1002</account>
<taxcode>ESCR04</taxcode>
</line>
<line>
<entity>H</entity>
<account>1003</account>
<taxcode>ESCR04</taxcode>
</line>
<line>
<entity>H</entity>
<account>1004</account>
<taxcode>ESCR04</taxcode>
</line>
<line>
<entity>H</entity>
<account>1005</account>
<taxcode>ESCR0</taxcode>
</line>
<line>
<entity>H</entity>
<account>1002</account>
<taxcode>ESCR0</taxcode>
</line>
</lines>
<Codes>
<Code>ESCR0</Code>
<Code>ESCR04</Code>
<Code>ESCR10</Code>
<Code>ESCR21</Code>
</Codes>
我需要确定代码中代码元素的数量,这些元素在“lines”中表示为lines>line>taxcode中的值。在这个例子中,它将是2
我知道如何用列出的代码之一找到“行”元素的数量,但我很难想出如何用另一种方法来处理它。有什么想法吗
感谢使用XPath 2.0和更高版本,您可以使用
count(/code/code[.=doc('lines.xml')/lines/line/taxcode])
使用XPath 2.0和更高版本,您可以使用count(/code/code[.=doc('lines.xml')/lines/taxcode])
是两个单独的文件/文档中的xml片段吗?那么您可能需要使用XQuery。xml片段是否在两个单独的文件/文档中?您可能需要使用XQuery,然后.OP可以合并这两个文件,并将xpath 1.0与count(//code/code[.=//lines/line/taxcode])结合使用。
OP可以合并这两个文件,并将xpath 1.0与count(//code/code[.=//lines/line/taxcode])结合使用。