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

RE: key() in match pattern of xsl:key

Subject: RE: key() in match pattern of xsl:key
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 10 Dec 2005 15:52:13 -0000
RE:  key() in match pattern of xsl:key
> Should it be possible to reference one key in the match pattern of 
> another?  

Yes, there's no ban on it, in either XSLT 1.0 or 2.0. But I haven't seen it
done very often.

> That 
> is, among the keys, is it `declaration before use' or `use before 
> declaration'?  Or either way?

No, there's no ban on forwards or backwards references. XSLT 2.0 makes it
explicit that circular references among keys must be detected and reported
as a dynamic error; in XSLT 1.0 this situation is left to the implementor,
and could possibly result in an infinite loop.
> 
> I find that this technique makes computing set differences 
> (and surely 
> there are other applications) readable, efficient, and scalable. For 
> example, given:
> 
>   <xsl:key name="keyB" match="B" use="." />
> 
> The variable AnotB stores the final set I'm after:
> 
>   <xsl:variable name="AnotB" select="//A[ not( key( 'keyB', . 
> ) ) ]" />

Nice idea. However we need to be clear that we're talking here about sets
based on node values, not node identity. Though the same approach could be
used for sets based on identity by using generate-id() as the "use"
expression. 
> 
> I have tested this computation with libxslt 1.1.15.  Although Daniel 
> Veillard has informed me that this usage is currently outside 
> the realm of 
> specified functionality, the above does work for my simple 
> test cases. 

The spec doesn't define any restrictions in this area, so implementations
are not allowed to impose any restrictions.

Michael Kay
http://www.saxonica.com/

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.