Re: [xsl] keys with composite values

Subject: Re: [xsl] keys with composite values
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Thu, 18 Jul 2002 23:30:41 +0200
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