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

RE: How to use xsl:key to get all values?

Subject: RE: How to use xsl:key to get all values?
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 12 Apr 2001 23:45:16 +0100
xsl get all nodes
> The problem is that I can't get expected result "1" "2". I
> don';t know how
> to get it.
> I have to use the key() in the project I am working on.

Well this particular key won't get you the answer you (incorrectly) expect,
because each call on key() gives you all the values with that key, and
<xsl:value-of> then takes the first one.

You could use a composite key formed by
use="concat(generate-id(ancestor::C), '/', @aField)"

Mike Kay
>
> Thanks again!
>
> Di
>
>
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
> Wendell Piez
> Sent: Thursday, April 12, 2001 1:12 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  How to use xsl:key to get all values?
>
>
> Hello Di,
>
> At 10:45 PM 4/12/01, you wrote:
> >Hi,
> >
> >Based on the following XML and XSL file, I'd like to output
> "1"  "2". But I
> >just get "1" "1". Any body can tell me what is wrong with
> ><xsl:key>
>
> Nothing's wrong with it, it's working fine.
>
> xsl:key indexes nodes across the entire document. When you write
> >                 <xsl:variable name="child"
> select="key('key-name', 'a1')"
> />
>
> You are setting the variable $child to be *all* the nodes
> that match the
> key with key value 'a1'. In your example, there are two such
> nodes, and you
> always get both of them regardless of the context node (since
> the value you
> give is always 'a1').
>
> When you ask for
> >                         <xsl:value-of select="$child/@value" />
>
> You get the value of the node set, which is defined as the
> string value of
> the first node in the node set in document order. That's
> always the same
> node, the one with value='1', because the node set is always
> the same and
> document order doesn't change either.
>
> It's unclear why you are using the key. Why not just:
>    <xsl:for-each select="CC">
>      <xsl:value-of select="DD/EE/@value" />
>    </xsl:for-each>
>
> ?
>
> Hope that helps,
> Wendell
>
> p.s. what's that namespace declaration
> xmlns="http://www.w3.org/TR/WD-xsl"
> doing for you anyhow?
>
> ><?xml version="1.0"?>
> ><AA>
> >         <BB>
> >                 <CC>
> >                         <DD>
> >                                 <EE aField="a1" value="1"/>
> >                         </DD>
> >                 </CC>
> >                 <CC>
> >                         <DD>
> >                                 <EE aField="a1" value="2"/>
> >                         </DD>
> >                 </CC>
> >         </BB>
> ></AA>
> >
> >
> ><?xml version="1.0"?>
> ><xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >         xmlns="http://www.w3.org/TR/WD-xsl" version="1.0">
> >
> >     <xsl:output method="text"/>
> >     <xsl:key name="key-name" match="EE" use="@aField" />
> >     <xsl:template match="AA/BB">
> >         <xsl:for-each select="CC">
> >                 <xsl:variable name="child"
> select="key('key-name', 'a1')"
> />
> >                         <xsl:value-of select="$child/@value" />
> >           </xsl:for-each>
> >     </xsl:template>
> >
> ></xsl:transform>
>
> ======================================================================
> Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc.                http://www.mulberrytech.com
> 17 West Jefferson Street                    Direct Phone: 301/315-9635
> Suite 207                                          Phone: 301/315-9631
> Rockville, MD  20850                                 Fax: 301/315-8285
> ----------------------------------------------------------------------
>    Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.