[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: document and key functions in xslt

Subject: Re: document and key functions in xslt
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 20 Aug 2001 16:03:06 +0100
xslt document key
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.