Re: [xsl] Re: Generate Id's usage as primary and foriegn key in the database!!

Subject: Re: [xsl] Re: Generate Id's usage as primary and foriegn key in the database!!
From: David Tolpin <dvd@xxxxxxxxxxxxxx>
Date: Sat, 25 Oct 2003 16:00:09 +0500 (AMST)
> > For a given xsl file when i run one xml file, i get generate id which are
> same
> > when i change the input xml file having the same structure and based on
> same
> > dtd.  I am using msxsl as XSLT engine for processing my input xml files.
> >
> > My questions are
> > 1)Can generate-id() be used to serve purpose like this ?
> > 2)Is there any other technique avaialable in XSL 1.0 to do the same ?
> >From the XSLT 1.0 spec (
> "An implementation is under no obligation to generate the same identifiers
> each time a document is transformed. There is no guarantee that a generated
> unique identifier will be distinct from any unique IDs specified in the
> source document."

This is not related to the problem described, by the way. The question is just
the opposite: how to ensure that different documents have non-intersecting sets 
of identifiers.

The answer is that an nmtoken, unique for each document in the set, such an
arbirtrary identifier concatenated with a sequential number of the document in
the set, must be passed to the stylesheet as a paramter and concatenated with
each generated identifier. And the URI of each document would serve well enough
except that the URI contains characters not allowed in identifiers.

> A more stable unique key generation is to use the XPath expression that
> selects exactly the node, concatenated with the URI of the xml document.

1) What does 'more stable unique key generation' mean? Is there such are thing
as 'almost unique keys'?

2) I don't see how this solves the problem, given that concatenation of a node-set and URI (a string)
will give a string which is not an indentifier, and 


will generate identical sets of identifiers on different documents of identical structure
regardless of $uri's value on most XSLT processors.

What exactly should be concatenated?

To ensure that identifiers in different documents generated using the same stylesheet and processor
are different, a unique prefix should be passed.

In a pseudocode:

for file in file-list
  xslt file stylesheet prefix=concat('a',next-number())

where next-number() yields the next number from a sequence [1,2,3,...]

and the stylesheet says

<xsl:attribute name="id">
  <xsl:value-of select="concat(prefix,generate-id(.))"/>

A solution for the problem not contained explicitely in the original question, but following
from the spec's quote (that is, how to ensure that generated identifiers are different from
all other identifiers in the same document) is at:

David Tolpin

 XSL-List info and archive:

Current Thread