You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Martin Goik <go...@hdm-stuttgart.de> on 2002/08/11 21:31:56 UTC

XSLT generate-id() and xalan java API

<Part_A>
When I use apache's xalan implementation to format an xml document by an
xsl stylesheet using the xslt standard function generate-id() I get
unique identifiers for each node of the document. Now I am looking for a
corresponding method in the xalan Java API to get identical values for
the corresponding nodes when processing the same xml document instance
by a java application. I first tried the deprecated
org.apache.xpath.DOMHelper.getUniqueID(Node n) method but apparently
this beast generates a different set of unique identifiers for the nodes
of the same xml document instance than the (xalan based) xslt
application org.apache.xalan.xslt.Process does. Then I looked into the
API and foung generate_idF in the TDM part, but the xalan-j
implementation reveals that all corresponding unique identifiers start
with a capital "N" as well, but none of the xslt generated documents
from my toy example ever receives an identifier starting like that. And
I was unable to comprehend the XSLT engine's implementation to see which
algorithm is used to derive unique id's.

Interestingly the saxon xslt implementation's generate-id() function
generates exactly the same ID's as xalan-j.
</Part_A>

<Part_B>
So If someone might give me a hint I'd greatly appreciate it.
Alternatively I'm looking for another way to solve the following
problem. Given:

 1) A XML document instance
 2) A xsl stylesheet with <xsl:template match="...">... rules but
without an entry rule like <xsl:template match="/">... 
 3) A java DOM application. 

Now the java DOM application has some magic algorithm to select a set M
of Element nodes from the xml document instance. For each node of this
set a matching template is guaranteed to be defined in the xsl
stylesheet. The application shall start an xslt formating process for
each node belonging to the set M by using the stylesheet.

If for each node in M an attribute of type ID is defined the problem can
be solved by coding the java application to add a template to the
stylesheet via DOM prior to formatting like:

<xsl:template match="/">
  <xsl:apply-templates select="id(xxx)"/>
</xsl:template>

In the absence of ID attributes I wanted to define a global   <xsl:key
name="uniqueId" match="//*" use="generate-id()"/> directive and
substitute select="id(xxx)" by select="key('uniqueId', xxx)" where xxx
is constructed from the active context of M  by the missing id
generating method decribed in Part_A. But maybe I'm misleaded an there
is a much simpler way to solve this problem?

</Part_B>
-- 
Martin Goik  Tel. +49-(0)711-685-8365  http://www.HdM-Stuttgart.de/~goik
Those who can, do. Those who cannot, teach. Those who cannot teach,
administer.