Re: [xsl] Use document() function to get a reference to the input doc

Subject: Re: [xsl] Use document() function to get a reference to the input doc
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Jul 2006 22:25:03 -0400
At 2006-07-17 17:54 -0400, Wendell Piez wrote:
A variable holding the input document is usually simply

<xsl:variable name="main-doc" select="/" />

Perhaps you're over-remembering? No document() function needed.

Now that this has brought my attention to what Charles *really* wanted and not what I thought I read, there is a nuance that was recently brought to my attention.

I'm told that generate-id(/) is not equal to
generate-id(document("",/)) ... when I thought it
was obvious that it should be.

So, in my XSLStyle stylesheet, when tracing
through import statements trying to detect
recursive references, I was unable to use the
simple test above that I've written in prose.

I ended up having to store the input document's document element as follows:

<xsl:variable name="xs:input-document-element" select="document('',/)/*"/>

And only then would my generate-id() give me what
I needed to detect an incorrect use of xsl:import
... without doing it that way, just using generate-id(/*), wouldn't work.

When I brought this issue up off-list, this is the response I received:

> I'm getting two different generate-id()
> values for the same document's root node.

That's because they aren't the same document... they are two different
documents loaded from the same URL.

That can't happen if they were both loaded using the document() function -
but in this case, one was and one wasn't, so there are no guarantees.

So my problem went away when I used "document('',/)". I'm taking the above answer I was given on faith: I'm not sure how the same URL produces two different documents in XSLT ... I've always thought it would be the same document if the same URL and generate-id() would produce the same value.

Sorry, Charles, to have misunderstood your original post.

. . . . . . . . Ken

--
Registration open for UBL training:    Montrial, Canada 2006-08-07
Also for XSL-FO/XSLT training:    Minneapolis, MN 2006-07-31/08-04
Also for UBL/XML/XSLT/XSL-FO training: Varo,Denmark 06-09-25/10-06
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread