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

Re: Fwd: xsl:key() and $variables.

Subject: Re: Fwd: xsl:key() and $variables.
From: Michael B Allen <mba2000@xxxxxxxxxx>
Date: Fri, 21 Jul 2006 22:20:44 -0400
key illustration
On Fri, 21 Jul 2006 18:42:29 -0400
Steve <subsume@xxxxxxxxx> wrote:

> ---------- Forwarded message ----------
> From: Steve <subsume@xxxxxxxxx>
> Date: Jul 20, 2006 3:41 PM
> Subject: xsl:key() and $variables.
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> I have a variable containing
> <Records>
>    <Record>
>       <activity>Baseball</
>       <hours>36</
>    <Record>
>       <activity>Shopping</
>       <hours>39</
>    <Record>
>       <activity>Writing</
>       <hours>3</
>     ......etc  (yes, I know they're not closed.)
> and some xml (document('../blah.xml') containing...
> <activities>
>     <activity neccesary="no">Baseball</
>     <activity neccesary="no">Shopping</
>     <activity neccesary="yes">Writing</
> ..............
> How do I  <xsl:apply-templates select="$variable/Records/Record[1]" />
> only those records which are neccesary="yes"  ?

First, I don't think XSLT was designed to do SQL style joins. It's not
a database API.

But. That doesn't mean you can't do it.

You could do a call-template() that does for-each on
activities/activity[@necessary='yes'] and return the Record that has an
activity/text() equal to the desired activity.

> I swear one of these posts I'll have xsl:key figured out.

I've never heard of xsl:key but the second illustration here:


looks useful. It seems an xsl:key is like a variable containing
a list of elements that match the xpath expression. But the key()
function allows you to filter on that list further by providing a key
(overloaded term warning). So in the above illustration the xsl:key
statement builds a list of Employee elements and indicates that the SSN
child should be used when a key is supplied to the key() function. So
the key('people',@emp) call says, "fetch all elements in the 'people'
list using the SSN @emp. Presumably each Employee would have a unique
SSN and therefore the key() call will return one Element.


Michael B Allen
PHP Extension for SSO w/ Windows Group Authorization

Current Thread


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.
First Name
Last Name
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.