Re: [xsl] xsl:key() and $variables.

Subject: Re: [xsl] xsl:key() and $variables.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Jul 2006 17:34:54 -0400
At 2006-07-20 15:41 -0400, Steve wrote:
I have a variable containing
...
and some xml (document('../blah.xml') containing...
...

It would help next time if you could supply the code that you already have so that it takes less time for others to modify it.

How do I  <xsl:apply-templates select="$variable/Records/Record[1]" />
only those records which are neccesary="yes"  ?

I'm not sure what you are asking, are you asking what principles to use, or are you asking someone to supply you with an answer? Below is an answer, though I'm not sure what aspect of the problem you are having issues with that caused you to ask the question to the list.

I hope this helps.

. . . . . . . . . . Ken

t:\ftemp>type blah.xml
<?xml version="1.0" encoding="US-ASCII"?>
<activities>
  <activity necessary="no">Baseball</activity>
  <activity necessary="no">Shopping</activity>
  <activity necessary="yes">Writing</activity>
</activities>

t:\ftemp>type steve3.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="2.0">

<xsl:output method="text"/>

<xsl:key name="activities" match="activity" use="@necessary"/>
<xsl:key name="records" match="Record" use="activity"/>

<xsl:template match="/">
  <xsl:variable name='records'>
    <Records>
      <Record>
        <activity>Baseball</activity>
        <hours>36</hours>
      </Record>
      <Record>
        <activity>Shopping</activity>
        <hours>39</hours>
      </Record>
      <Record>
        <activity>Writing</activity>
        <hours>3</hours>
      </Record>
    </Records>
  </xsl:variable>

  <xsl:apply-templates
    select="key('records',
                key('activities',
                    'yes',
                    document('blah.xml')),
                $records)"/>
</xsl:template>

<xsl:template match="Record">
  <xsl:value-of select="'Activity: ',activity,', hours=',hours"
                separator=""/>
  <xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>xslt2 steve3.xsl steve3.xsl con
Activity: Writing, hours=3

t:\ftemp>

--
Registration open for UBL training:    Montrial, Canada 2006-08-07
Also for XSL-FO/XSLT training:    Minneapolis, MN 2006-07-31/08-04
Also for UBL/XML/XSLT/XSL-FO training: Varo,Denmark 06-09-25/10-06
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread