I would count all distinct items considering parent and child tag.
For example, if the document contains:
<root>
<A value="5.1">
<B value="3.5">
<C value="1.4">
<D value="0.2">
<E value="X"/>
</D>
</C>
</B>
</A>
<A value="5.1">
<B value="3.5">
<C value="1.4">
<D value="0.4">
<E value="Y"/>
</D>
</C>
</B>
</A>
<A value="4.6">
<B value="3.1">
<C value="1.5">
<D value="0.2">
<E value="X"/>
</D>
</C>
</B>
</A>
<A value="5.0">
<B value="3.6">
<C value="1.4">
<D value="0.2">
<E value="X"/>
</D>
</C>
</B>
</A>
</root>
I would count all distinct items for AB, ABC, ABCD, BCD etc.
I tried this xquery command, but got only the distinct values for individual items:
count(distinct-values(doc('partitioncollection')/root/A/@value)) -> 3
count(distinct-values(doc('partitioncollection')/root/B/@value)) -> 3
count(distinct-values(doc('partitioncollection')/root/C/@value)) -> 2
More specifically, if I want calculate the counts of all possibile pairs of value, the results should show:
A/B : 3
A/B/C : 3
A/B/C/D : 4
A/B/C/D/E : 4
B/C : 3
B/C/D : 4
B/C/D/E : 4
C/D : 3
C/D/E : 3
D/E : 2
C/E : should be 3 because there are 3 distinct pairs of values:
<C value="1.4"><E value="X"/>
<C value="1.4"><E value="Y"/>
<C value="1.5"><E value="X"/>
A/D : should be 4 because there are 4 distinct pairs of values:
<A value="5.1"><D value="0.2">
<A value="5.1"><D value="0.4">
<A value="4.6"><D value="0.2">
<A value="5.0"><D value="0.2">
etc.
Being computationally complex, I believe it is easier to create a function that takes as a single set of tags (i.e. A-D or C-E etc.) and returns the value of the counter
AandBelements form a "pair" of parent/child elements, but why is "ABC" a pair, why "BC" not? And is that document structure known to contain only the same kind of elements in the same nesting structure so it suffices to look downwards and compare@valueattributes or is the an arbitrary number and name and nesting of elements? - Martin Honnen