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

Understanding xsl:key

Subject: Understanding xsl:key
From: "Heiner de Wendt" <H.dewendt@xxxxxxxxx>
Date: Thu, 17 Aug 2000 12:42:10 +0200
Understanding xsl:key
Hello,

I've got trouble understanding the proper use of xsl:key and the 
key() function. Here's my XML-File:

<booklist>
 <book>
  <title>
   <name>Design Patterns</name>
  </title>
  <author>Erich Gamma</author>
  <author>Richard Helm</author>
  <author>Ralph Johnson</author>
  <author>John Vlissides</author>
 </book>
 <book>
  <title>
   <name>Pattern Hatching</name>
  </title>
  <author>John Vlissides</author>
 </book>
 <book>
  <title>
   <name>Building Applications</name>
  </title>
  <author>Mohamed Fayad</author>
  <author>Douglas C. Schmidt</author>
  <author>Ralph Johnson</author>
 </book>
</booklist>

Here's the XSL:

 <xsl:key name="test" match="title" use="name"/>

 <xsl:template match="booklist">
  <booklist>
   <xsl:apply-templates/>
  </booklist>
 </xsl:template>

 <xsl:template match="book">

  <xsl:if test="key('test','Pattern Hatching')">
   <node>
    <xsl:value-of select="."/>
    <xsl:text> -EndOfKeyValue-</xsl:text>
   </node>
  </xsl:if>

 </xsl:template>


Now, I'd expect the xsl:if to make sure only "name" elements that are 
children of "title" and have the content "Pattern Hatching"  are 
shown. Instead, I get ALL contents, including the author names; only 
the various "book" contents are (naturally) placed into single 
"node" elements.

Now, to make a long question short: WHY??? :)

Thanks,

Heiner
(who's read all "key"-explanations that he could find, but just seems 
to get something wrong)


 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.