I will give an example to better clarify myself.
Example:
<asdf>
<parentnode id ="1">
<childnode>
...
</childnode>
<childnode>
...
</childnode>
</parentnode>
<parentnode id ="2">
<childnode>
...
</childnode>
<childnode>
...
</childnode>
<childnode>
...
</childnode>
</parentnode>
<parentnode id ="3">
<childnode>
...
</childnode>
</parentnode>
</asdf>
I need to count all childnodes of all parentnodes and give back the minimum count of childnodes of the given parentnode with its id.
For this example the solution would be:
<parentnode id="3" amount="1"/>
I don't really know where to begin. Do I have to count distinct elements in a for loop or is this also possible with an Xpath expression ? I'm not sure if this is the right direction:
let $a := fn:doc('asdf.xml')/asdf/*
return
for $z in distinct-values($a/name() = childnode )
order by count($z) ascending
return $z)[1]