Hi Everyone,

I am using Xalan-J 2.7.1 and I have been struck with a weird behavior of the xslt function key() - which I believe is an error.

If I define a variable like:
<xsl:variable name="var" select="key('nidkey', //nref/@nref)"/>

And use the $var as an argument for the exslt.org set funtion "difference" I get the following error: java.lang.RuntimeException: Programmer assertion is incorrect! - Can not get a DTM Unless a DTMManager has been set!

If I instead define the variable var as:
<xsl:variable name="var" select="key('nidkey', //nref/@nref)/self::node()"/> Everything works! - but adding "/setf::node()" to something that is already a nodeset
should not be necessary

I this an error?

Best regards
Christoffer Dam Bruun


Test transform and data here:
key-bug-test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <a nid='xx'></a>
  <b nid='yy'></b>
   <c nid='zz'></c>
  <nref nref='xx'/>
  <nref nref='yy'/>
</root>


key-bug.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
  xmlns:set="http://exslt.org/sets";>
    <xsl:output method="xml" indent="yes"/>
  <!--  make a key of all elements that have a @nid attribute -->
  <xsl:key name="nidkey" match="//*...@nid]" use="@nid"/>
    <xsl:template match="root">
            <xsl:variable name="abc_elements" select="//a | //b | //c"/>
<!-- with this definition if ab_element the call to set:difference fails with: java.lang.RuntimeException: Programmer assertion is incorrect! - Can not get a DTM Unless a DTMManager has been set! --> <xsl:variable name="ab_element" select="key('nidkey', //nref/@nref)"/> <!-- with this definition if ab_element the call to set:difference succeeds <xsl:variable name="ab_element" select="key('nidkey', //nref/@nref)/self::node()"/>
      -->
<xsl:message>ab_element size: <xsl:value-of select="count($ab_element)"/></xsl:message>
            <testoutput>
          <ab_element>
              <xsl:for-each select="$ab_element">
                  <xsl:copy-of select="."></xsl:copy-of>
              </xsl:for-each>
          </ab_element>
<xsl:variable name="diff" select="set:difference($abc_elements, $ab_element)"/> <xsl:message>diff size: <xsl:value-of select="count($diff)"/></xsl:message>
          <diff>
              <xsl:for-each select="$diff">
                  <xsl:copy-of select="."></xsl:copy-of>
              </xsl:for-each>
          </diff>          </testoutput>
  </xsl:template>
</xsl:stylesheet>

Reply via email to