Q:More challenges ;-)

How can I sort documents on subnodes, where the subnodes occur more than once, e.g.


3
4



1
2




In this example A with id 2 must be placed before 1 in the final result.

Regards,
Rudolf de Grijs

Hi Rudolf,

the following XQuery will do the job:
xquery=input()/A sort by (min(B))

Regards

Harald

Thank you Harald, but I don not think that this will work.

min(sequence) returns minimum value and sort by expects ordering expression leading to a runtime type exception (INOXQE6301).

Kind regards,
Rudolf

Rudolf,

if B is defined as an element with type xs:string, the query works as I have posted it.
I have noticed that the query yields a runtime type exception when B is defined as xs:integer.

Regards

Harald

Hi Harald,

Does this mean that it works as designed or are we talking about a bug?

Regards,
Rudolf

Hi Rudolf,

for xs:string, it works as designed. For xs:integer, it’s a bug.

Regards

Harald