[ACCEPTED]-How do I use XPath to count the number of nodes with a certain attribute-count
Accepted answer
I reproduced it using XPathBuilder 2.0.0.4. However 6 the XPath expression works and evaluates 5 correctly in an online evaluator I tried 4 (http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm).
EDIT: Also tried with latest version 3 of Altova XMLspy
input:
<?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>
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>
output:
<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsi="n/a">4</output>
I think 2 it's XPathBuilder thats doing something 1 wrong.
Using the above xml saved into a test.xml 1 and using the tool http://kernowforsaxon.sourceforge.net/
declare namespace xsi="n/a";
count(doc('test.xml')//Device[@xsi:type = "EndDevice"])
Produces the right output.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.