xalan-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hall, Kurt (Truven Health)" <kurt.h...@truvenhealth.com>
Subject bug(?) when reusing a xsl:key across multiple templates
Date Tue, 15 Oct 2013 18:48:03 GMT
I suspect that I have found a bug pertaining to multiple key() function calls that share a
common xsl:key but occur in different templates.  Both key() calls are operating on results-tree-fragments
that I've turned into nodesets with the xalan:nodeset() extension.

When the calls are in different templates the second occurance of key() doesn't return any
results.  If I combine template1 and template2 into a single template then I get correct results
for both key() calls.  I have worked around the issue by cloning the xsl:key (key2) and no
longer reusing them.

I'm using Xalan 2.7.1.

====== Template 1 ======
====== Template 2 ======

Test Code:
<?xml version="1.0"  encoding = "ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan"

  <xsl:key name="key1" match="*" use="text()"/>
  <xsl:key name="key2" match="*" use="text()"/>

  <xsl:template match="/">
      <xsl:call-template name="template1"/>
      <xsl:call-template name="template2"/>
      <xsl:call-template name="template3"/>

  <xsl:template name="template1">
      <xsl:message>====== Template 1 ======</xsl:message>
      <xsl:variable name="rtf1"><N1>1</N1><N2>2</N2></xsl:variable>
      <xsl:variable name="tree1" select="xalan:nodeset( $rtf1)"/>
      <xsl:message>count(tree1)=<xsl:value-of select="count( $tree1/*)"/></xsl:message>
      <xsl:variable name="uniqNodes" select="$tree1/*[generate-id() = generate-id( key(
'key1', text()))]"/>
      <xsl:for-each select="$uniqNodes">
        <xsl:message><xsl:value-of select="local-name()"/>=<xsl:value-of select="text()"/></xsl:message>

  <xsl:template name="template2">
      <xsl:message>====== Template 2 ======</xsl:message>
      <xsl:variable name="rtf2"><N4>4</N4><N5>5</N5><N6>6</N6></xsl:variable>
      <xsl:variable name="tree2" select="xalan:nodeset( $rtf2)"/>
      <xsl:message>count(tree2)=<xsl:value-of select="count( $tree2/*)"/></xsl:message>
      <!-- ************  CHANGE FOLLOWING FROM key1 to key2 ************* -->
      <xsl:variable name="uniqNodes" select="$tree2/*[generate-id() = generate-id( key(
'key1', text()))]"/>
      <!-- ************************************************************** -->
      <xsl:for-each select="$uniqNodes">
          <xsl:message><xsl:value-of select="local-name()"/>=<xsl:value-of


Thanks for any help,
(This is my first post to the user-group so forgive me if I'm not following proper protocol)

Kurt Hall
Principal Engineer
Truven Health Analytics
Phone: 303-486-9161
The Healthcare Business of Thomson Reuters is now
Truven Health Analytics.

View raw message