Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 对列表中以XML元素中的值表示的值进行计数。_Xpath - Fatal编程技术网

Xpath 对列表中以XML元素中的值表示的值进行计数。

Xpath 对列表中以XML元素中的值表示的值进行计数。,xpath,Xpath,我有这样一些XML: <lines> <line> <entity>H</entity> <account>1002</account> <taxcode>ESCR04</taxcode> </line> <line> <entity>H</entity> <account>1003<

我有这样一些XML:

<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])结合使用。