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

Re: keys with composite values

Subject: Re: keys with composite values
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Thu, 18 Jul 2002 23:30:41 +0200
Re:  keys with composite values
Borenstein, Philip wrote:
I'm getting some unexpected results with keys that use composite values.
...
What I get depends on the other of VERSION elements:
	key('features', '11') => Slices
	key('features', '10') => Dices (but not Slices)
...
This happens in both Saxon and MSXSL, so I'm guessing there's something I'm
not understanding about keys with composite values.

XML source:

<FEATURES>
	<FEATURE NAME="Slices">
		<VERSION MAJOR="1" MINOR="1"/>
		<VERSION MAJOR="1" MINOR="0"/>
	</FEATURE>
	<FEATURE NAME="Dices">
		<VERSION MAJOR="1" MINOR="0"/>
	</FEATURE>
</FEATURES>

XSLT stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="features"
	match="FEATURE[VERSION]"
	use="concat(VERSION/@MAJOR,VERSION/@MINOR)"/>

You are matching FEATURE elements. The key used for the "Dices" element is easy: '10'. The "Slices" element has two VERSION childs, which means that both VERSION/@MAJOR andd VERSION/@MINOR evaluate to node sets with two nodes in it, coercing to strings results in the key '11'. This means key("features","11") will get the "Slices" feature only, and key("features","10" gets only "Dices".

In order to get what you want you'll have to match
the VERSION elementsand then use the parent. Try

 <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:key name="features"
 	match="VERSION"
 	use="concat(@MAJOR,@MINOR)"/>
   <xsl:template match="FEATURES" >
	<CONTENT>
           <xsl:copy-of select="key('features', '11')/.." />
	</CONTENT>
  </xsl:template>
 </xsl:stylesheet>


J.Pietschmann



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.