如何使用XPath计算具有特定属性的节点数

Jas*_*ung 28 xpath count

我似乎无法获得XPath表达式来适应我的场景.我想找到所有类型为"EndDevice"的"Device"节点.我能够计算所有"设备"节点,并且我还能够找到具有"EndDevice"属性的所有"设备"节点.但是,我似乎无法将它们结合起来!

count(//Device) //works
//Device[@xsi:type='EndDevice'] //works
count(//Device[@xsi:type='EndDevice']) //doesn't work
Run Code Online (Sandbox Code Playgroud)

如果重要,我正在使用XPathBuilder.

Led*_*und 21

我使用XPathBuilder 2.0.0.4重现了它.但是XPath表达式在我尝试的在线评估器中正常工作和评估(http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm).

编辑:也尝试了最新版本的Altova XMLspy

输入:

<?xml version="1.0"?>
<asdf xmlns:xsi="n/a">
    <Device xsi:type='EndDevice'/>
    <Device xsi:type='EndDevice'/>
    <Device xsi:type='EndDevice'/>
    <Device xsi:type='EndDevice'/>
</asdf>
Run Code Online (Sandbox Code Playgroud)

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsi="n/a">
    <xsl:output indent="yes"/>
    <xsl:template match="*">
        <output>
            <xsl:value-of select="count(//Device[@xsi:type = 'EndDevice'])"/>
        </output>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

输出:

<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsi="n/a">4</output>
Run Code Online (Sandbox Code Playgroud)

我认为这是XPathBuilder做错了什么.