XQuery > Counting preceding nodes

Hello there,

As Tamino’s XQuery implementation is missing the preceding reverse Axis, I was wondering if there was any way to perform the following task.

Let’s say I have this XML document :

001 002 019 020

Chapter are recursive and can contain any number of terminal Article nodes.

What I want to do is to select an article from its id (eg “020”), and count how many preceding Article nodes I have (eg 19). That is its position among all other Articles.

Axis preceding::Article, would be great, but it is not implemented yet.

I developped an SXS to count Article using SAX, but this messes my Tamino DB’s memory (Memory Allocation Failed).

Any ideas ?

Thanks in advance.

Hi,

I have to admit that the preceding axis is not supported by Tamino XQuery. This is due to the fact that the preceding axis is optional. Moreover I’m afraid that there is no other way to express the preceding axis with Tamino 4.2 (except writing an sxs function). The good news is that the upcoming Tamino version will support order comparisons which allow you to count the predecessors of a given node.

Best Regards,

Thorsten Fiebig

Hi,

if your Article-IDs are really sorted as your sample suggests, it is
possible with:

let $root := …
let $article := $root//Article[.=“020”]
return count($root//Article[. < $article])

Regards,
Juliane.

Thanks for you replies.

Unfortunately my ids are not sorted (these are dynamically generated ids). Indeed they are in my example, but that was for simplicity sake.

Cheers