Re: [xsl] determining position of a document included using document function

Subject: Re: [xsl] determining position of a document included using document function
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 10:46:13 +0000
Gennady Loskutov wrote:
> I use generate-id() function to identify the included file.
> Basically, the idea is to match generated id for the root element of
> the current node with ones, generated separately and stored in a
> variable. According to XSLT spec,
> generate-id(document("foo.xml"))=generate-id(document("foo.xml")) is
> always true, so I assume that
> generate-id(document("foo.xml"))=generate-id(document(/files/file/@href))
> must be also true if the "foo.xml" file is among those specified in
> /files/file/@href.
> To use my solution, you must use an extension function to transform
> a result tree fragment stored in a variable into a node set (I use
> Microsoft XML parser, which has node-set() function).

That's a really good idea. I don't think that you need to use the
node-set() extension function to implement it, though...

You can store all the file elements in a global variable:

<xsl:variable name="files" select="/files/file" />

Then within the template that's processing one of the nodes in the
document that the file element references, you can first generate the
ID of the root node for that document:

  <xsl:variable name="doc" select="generate-id(/)" />

And then look at all the file elements (stored in that global
variable) to find the one where, when you retrieve the document
associated with its href attribute and generate an ID for it, you get
the same generated ID as the one stored in $doc:

  <xsl:variable name="file"
    select="$files[generate-id(document(@href)) = $doc]" />

And then you can count how many preceding sibling file elements it has
to work out its position:

  <xsl:variable name="position"
    select="count($file/preceding-sibling::file) + 1" />



Jeni Tennison

 XSL-List info and archive:

Current Thread