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

Re: xsl:key() and $variables.

Subject: Re: xsl:key() and $variables.
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Jul 2006 17:34:54 -0400
Re:  xsl:key() and $variables.
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

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.