The resulting node set of the key-function over
multiple times defined key contains not the correct
count of nodes (See result document below).
This behaviour applies also to imported key
definitions.
The test document (doc.xml):
<?xml version="1.0" encoding="UTF-8"?>
<doc >
<indexterm>
<primary>First</primary>
</indexterm>
<indexterm>
<primary>Second</primary>
</indexterm>
<indexterm>
<primary>Second</primary>
</indexterm>
<indexterm>
<primary>Third</primary>
</indexterm>
</doc>
The test stylesheet (doc.xsl):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:key name="primary" match="indexterm" use="primary"/>
<xsl:key name="primary" match="indexterm" use="primary"/>
<xsl:template match="/">
<xsl:apply-templates
<!-- select every primary keyword only once -->
select="//indexterm[count(.|key('primary',primary)[1])
= 1]"/>
</xsl:template>
<xsl:template match="indexterm">
<xsl:text>
Test for '</xsl:text>
<xsl:value-of select="primary"/>
<xsl:text>' yields </xsl:text>
<xsl:value-of select="count(key('primary',primary))"/>
<xsl:text> Entry/ies.</xsl:text>
<!--
<xsl:for-each select="key('primary',primary)">
<xsl:value-of select="." />
</xsl:for-each>
-->
</xsl:template>
</xsl:stylesheet>
SAXON (6.4.4/6.5) command line:
saxon -o saxtest.txt doc.xml doc.xsl
The result document (saxtest.txt):
Test for 'First' yields 1 Entry/ies.
Test for 'Second' yields 4 Entry/ies.
Test for 'Third' yields 1 Entry/ies.
Logged In: YES
user_id=251681
Confirmed as a bug: when there are two or more key
definitions with the same name, and these overlap in the
sense that the same value can be obtained from more than
one key definition, then the nodes in the index are not
necessarily stored in document order, and may contain
duplicates. In some cases, the duplicates will be
eliminated at retrieval time, but not always (and the
details vary between 6.5 and 7.0).
Applies to 6.5, 7.0, and all earlier versions.
Now fixed in both code branches (in KeyManager).
New test case added: idky15
Mike Kay
Logged In: YES
user_id=251681
Cleared in 6.5.1, still present in 7.0
Logged In: YES
user_id=251681
Cleared in 7.1