Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2244

xsl:sort does not work with nodeset parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • XSLTC
    • None
    • JDK 1.5.0_06

    Description

      i create some number elements within a variable, pass them to a function that extract the maximum value, and i get an empty result.
      this happens width jdk 1.5 default transformer, but not with Saxon transformer or jdk 1.4.2 default transformer.

      simple function to calculate the maximum value of some nodes passed as parameter :
      <xsl:template name="max">
      <xsl:param name="nodes" select="/.."/>
      <xsl:for-each select="$nodes">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position() = 1">
      <xsl:value-of select="number(.)"/>
      </xsl:if>
      </xsl:for-each>
      </xsl:choose>
      </xsl:template>

      simple elements :
      <xsl:variable name="foo">
      <xsl:element name="bar">
      <xsl:text>5</xsl:text>
      </xsl:element>
      <xsl:element name="bar">
      <xsl:text>8</xsl:text>
      </xsl:element>
      <xsl:element name="bar">
      <xsl:text>2</xsl:text>
      </xsl:element>
      </xsl:variable>

      call the function :
      <xsl:variable name="result">
      <xsl:call-template name="max">
      <xsl:with-param name="nodes" select="nodeset($foo)/bar"/>
      </xsl:call-template>
      </xsl:variable>

      see the result :
      <xsl:value-of select="$result" /> is empty

      If i remove the <xsl:sort ...> line in the function, result is 5 (wich is logic)

      If i use the function inline, it works :
      <xsl:variable name="result">
      <xsl:for-each select="nodeset($foo)/bar">
      <xsl:sort data-type="number" order="descending"/>
      <xsl:if test="position() = 1">
      <xsl:value-of select="number(.)"/>
      </xsl:if>
      </xsl:for-each>
      </xsl:variable>
      <xsl:value-of select="$result" /> is 8

      Attachments

        1. bug.xslt
          1 kB
          Nicolas
        2. XALANJ_2444_Test.java
          8 kB
          Cyrille Le Clerc

        Activity

          People

            Unassigned Unassigned
            oiseau Nicolas
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: