Given the following XML file :
<a m="1">
<b n="1" o="2">
<c p="3">3</c>
<d/>
</b>
<b n="1" o="2">
<c p="3">3</c>
<d q="3">
<e r="2">2</e>
</d>
<f s="1"/>
</b>
</a>
How can I find the following expressions :
1. count(/*/*/*) = 5
2. count (/*//*) = 6
3. count (/*/*//@*) = 4
I ran the xml file with those xpath expressions in Java , but I don’t understand why the answers are 5,6,4 .
Can someone please explain how can I calculate the above expressions (not using a java code) but by understanding the actual concept of the commands /*/*/* and /*//* and /*/*//@* ?
Much appreciated
This selects all “grand-children of the top element — these are:
c,d,c,dThis selects all descendant elements of the top element:
b,c,d,b,c,d,e,fThis selects all attributes either of children of the top element or of their descendants:
n,o,p,n,o,p,q,r,s.Therefore, the counts produced must be, respectively:
XSLT – based verification:
When this transformation is performed on the provided XML document (never, never ever present the document with a picture!!!):
The Xpath expressions are evaluated and their results are copied to the output: