[xsl] keys with composite values

Subject: [xsl] keys with composite values
From: "Borenstein, Philip" <pb@xxxxxxxxxx>
Date: Thu, 18 Jul 2002 17:08:42 -0400
I'm getting some unexpected results with keys that use composite values. The
problem, distilled to the minimum looks like this: I want to retrieve the
FEATURE elements that satisfy particular VERSIONs. For example, if I specify
version 1.0, I want to get both 'Slices' and 'Dices'. If I specify version
1.1, I want only 'Slices'.

I use a composite key for the version. It seems I should be able to say
key('features', '10') for version 1.0 features and key('features', '11') for
version 1.1 features.

What I get depends on the other of VERSION elements:

	key('features', '11') => Slices
	key('features', '10') => Dices (but not Slices)

If I switch the VERSION elements in the 'Slices' FEATURE:
	key('features', '11') => empty
	key('features', '10' => Slices and Dices

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)"/>

<xsl:template match="FEATURES" >
	<CONTENT>
		<xsl:copy-of select="key('features', '11')" />
	</CONTENT>
</xsl:template>
</xsl:stylesheet>

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


Current Thread