|
Subject: Re: [xsl] Fwd: xsl:key() and $variables. From: Michael B Allen <mba2000@xxxxxxxxxx> Date: Fri, 21 Jul 2006 22:20:44 -0400 |
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:
http://www.cranesoftwrights.com/resources/xslkeys/index.htm
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.
Mike
--
Michael B Allen
PHP Extension for SSO w/ Windows Group Authorization
http://www.ioplex.com/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Fwd: xsl:key() and $variables, Steve | Thread | Re: [xsl] Fwd: xsl:key() and $varia, Wendell Piez |
| Re: [xsl] Lookup, eliminating dupli, Manfred Staudinger | Date | Re: [xsl] xsl:key() and $variables., G. Ken Holman |
| Month |