RE: [xsl] How to use generate-id() inside an xsl:function without a node available?

Subject: RE: [xsl] How to use generate-id() inside an xsl:function without a node available?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 28 Feb 2007 00:11:15 -0000
> I found that when using generate-id() with LREs, it creates 
> increasing numbers, preceded by 'd'. When using source nodes, 
> something else happens. I know from the specs, that an 
> implementation can choose its own way of creating the ID. But 
> a (longer) while ago, I remember to have seen an explanation 
> of the algorithm used, but today I can't find it anymore 
> (searched the Net, saxonica.com, the faq and both of your 
> reference books).

You're referring of course to the Saxon algorithm - each processor can do
this its own way.

I don't think the Saxon algorithms are documented anywhere. There's
potentially a different algorithm for each of the supported tree models
(tinytree, linked tree, DOM, JDOM, DOM4J, XOM) and third-party tree models
can do their own thing. For the TinyTree the algorithm is:

        buffer.append("d");
        buffer.append(Integer.toString(tree.getDocumentNumber()));
        buffer.append(NODE_LETTER[getNodeKind()]);
        buffer.append(Integer.toString(nodeNr));

Note that the "tree" is really a forest - a sequence of trees, often only
one but not always - and the "document number" is actually a "forest
number". The node letter identifies the node kind, e.g. "e" for element, and
it's really redundant but you need some kind of separator between the
document number and the node number and this is as good as anything.

At one time in the distant past I used an identifier that doubled as a sort
key for sorting nodes into document order. This was just a monotonic
sequence number mapped to ascii using a mapping such as

0-9      a0-a9
10-99    b10-b99
100-999  c100-c999
etc

Michael Kay
http://www.saxonica.com/

Current Thread