2
我正在生成从XML文件中提取信息的报告。XPath 1.0:列出不同的值及其出现次数
<?xml version="1.0" encoding="UTF-8"?>
<JoinedRoot>
<FlexoPlateReport>
<Device>A</Device>
</FlexoPlateReport>
<FlexoPlateReport>
<Device>B</Device>
</FlexoPlateReport>
<FlexoPlateReport>
<Device>A</Device>
</FlexoPlateReport>
<FlexoPlateReport>
<Device>C</Device>
</FlexoPlateReport>
<FlexoPlateReport>
<Device>C</Device>
</FlexoPlateReport>
<FlexoPlateReport>
<Device>B</Device>
</FlexoPlateReport>
<FlexoPlateReport>
<Device>A</Device>
</FlexoPlateReport>
</JoinedRoot>
基本上,我到目前为止所做的工作是放在一起的XPath表达式,它将列出不同的设备。上面的XML中有三个设备(A,B和C)。以下是XPath表达式。
/JoinedRoot/FlexoPlateReport[not(Device/text()=preceding-sibling::FlexoPlateReport/Device/text())]/Device/text()
我只限于XPath 1.0,否则我会使用distinct-values()函数。接下来我想要做的是返回第一个XPath表达式中列出的每个设备的计数。例如,从上面的XML会给我以下罪状:
答:3
B:2
C:2
是否有可能在一个表达式返回这两个名称和数量?如果不是,是否有XPath表达式只会返回每个不同设备的计数。我永远不会知道报告中有多少个不同的设备,或设备元素的值。因此,我不能简单地为特定的设备名称写count()函数。
在此先感谢!
您运行此XPath 1.0的环境是什么? –
@ThomasW,我将在Esko的Automation Engine中将它用作SmartName。 –
我只能快速浏览一下文档,但在我看来,您可以使用Script SmartName。不确定Esko的JavaScript引擎是否支持XPath查询,但您始终可以使用JavaScript本身遍历文档。 –