Details
-
Bug
-
Status: Resolved
-
Critical
-
Resolution: Duplicate
-
2.7
-
None
Description
It seems that xsl:key generates one key entry for two different values of the key. Is this some type of hash collision?
Input file:
<root>
<Transaction num="1">
<PC>PRMI03SO</PC>
</Transaction>
<Transaction num="2">
<PC>PRMI03T0</PC>
</Transaction>
<Transaction num="3">
<PC>PRMI03T1</PC>
</Transaction>
</root>
Stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:key name="txn-by-account" match="Transaction" use="PC"/>
<xsl:template match = "/">
<xsl:apply-templates select="root"/>
</xsl:template>
<xsl:template match="root">
<Accounts>
<!-- select the first Transaction for each unique account -->
<!-- xsl:apply-templates select="Transaction[ generate-id() = generate-id(key('txn-by-account', PC)[1]) ]"/ -->
<xsl:apply-templates select="Transaction"/>
</Accounts>
</xsl:template>
<xsl:template match="Transaction">
<Account num="
" pc="
{PC}" count="
{count(key('txn-by-account', PC))}" gid="
{generate-id()}" gid1="
{generate-id(key('txn-by-account', PC)[1])}">
<PCs>
<xsl:for-each select="key('txn-by-account', PC)">
<xsl:value-of select="@num"/>
<xsl:text>=</xsl:text>
<xsl:value-of select="PC"/><xsl:text>, </xsl:text>
</xsl:for-each>
</PCs>
</Account>
</xsl:template>
</xsl:stylesheet>
Incorrect output:
java -server -Xmx384m -Xms32m org.apache.xalan.xslt.Process -edump -diag -IN /tmp/keybug.xml -XSL /tmp/keybug.xsl -XML
<?xml version="1.0" encoding="ISO-8859-1"?><Accounts><Account gid1="N10004" gid="N10004" count="2" pc="PRMI03SO" num="1"><PCs>1=PRMI03SO, 2=PRMI03T0, </PCs></Account><Account gid1="N10004" gid="N1000B" count="2" pc="PRMI03T0" num="2"><PCs>1=PRMI03SO, 2=PRMI03T0, </PCs></Account><Account gid1="N10012" gid="N10012" count="1" pc="PRMI03T1" num="3"><PCs>3=PRMI03T1, </PCs></Account></Accounts>
--------- Transform of /tmp/keybug.xml via /tmp/keybug.xsl took 334 ms
Since the values of all PC element are different in all three accounts, there should be three different entries in the key. However, as you can see, the key returns only two different entries. The key returns the same nodeset for matches PRMI03SO and PRMI03T0.
Attachments
Attachments
Issue Links
- duplicates
-
XALANJ-1955 Fail Oasis test case Keys_PerfRepro3
- Resolved