[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] document and key functions in xslt


Subject: Re: [xsl] document and key functions in xslt
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 20 Aug 2001 16:03:06 +0100

Hi Cornelia,

> 1. <xsl:for-each select="document('annuaire.xml')/key('mykey',$myname)">
> ...
> </xsl:for-each>
>
> where the result of the key function gives as result a node set of
> the annuaire.xml file

It doesn't work because it's not legal XPath 1.0 syntax. When a
function or a variable reference starts a path, it gives the initial
node set, the starting point of the rest of the path. You can't have
more than one function in a path (aside from within a predicate).

The way to do what you're trying to do with the above is to use:

  <xsl:for-each select="document('annuaire.xml')">
    <xsl:for-each select="key('mykey', $myname)">
      ...
    </xsl:for-each>
  </xsl:for-each>

However, the syntax you suggest is something that will probably be
permitted in XPath 2.0.

> 2. <xsl:template match="document('foo.xml')">
> ...
>
> document(...) gives as result the root node of the document so is
> equivalent with match="/"

The types of values that you can have in match attributes are
different from the kinds of values that you can have in select
attributes. The former are patterns which match nodes, and the latter
are expressions that select nodes.

Patterns look like XPaths, but they aren't, they're special to XSLT.
There are only two "functions" that are allowed at the beginning of an
XPath -- id() and key(). They're there to give the same kind of
functionality as you can get using IDs in CSS, I think.

But there's no way to test the origin of a node at the moment, aside
from laboriously testing whether the node is in the set of nodes from
a document with:

  count(.|document('foo.xml')/descendant-or-self::node()) =
  count(document('foo.xml')/descendant-or-self::node())

If you have a good use case for using document() in a match pattern, I
suggest sending it to the XSL WG at xsl-editors@xxxxxx, although it
might be that the "function to absolutize relative URIs" that should
be available in XSLT 2.0 would give you this functionality, e.g.:

  absolutize-uri('') = 'foo.xml'

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords