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

Error counting nodes when using a variable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Duplicate
    • 2.7
    • 2.7.1
    • Xalan
    • None
    • fp5

    Description

      Consider the following XML file:

      ---------------------------------------------------
      <xmldata>
      <value/>
      <value/>
      </xmldata>
      ---------------------------------------------------

      Consider the following XSL file:

      ---------------------------------------------------
      <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

      <xsl:variable name="doc" select="xmldata"/>

      <xsl:template match="xmldata">

      <html>
      <head/>
      <body>

      Number of elements: <xsl:value-of select="count($doc/value)"/>
      <br/>
      Number of elements: <xsl:value-of select="count($doc/value)"/>
      <br/>
      </body>
      </html>

      </xsl:template>
      </xsl:stylesheet>
      ---------------------------------------------------

      As you can see, the output should be an html page showing the total number of elements twice. However, this is the output:

      ---------------------------------------------------
      Number of elements: 2
      Number of elements: 4
      ---------------------------------------------------

      Now consider the following XSL file:

      ---------------------------------------------------
      <xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

      <xsl:template match="xmldata">

      <xsl:variable name="doc" select="."/>

      <html>
      <head/>
      <body>

      Number of elements: <xsl:value-of select="count($doc/value)"/>
      <br/>
      Number of elements: <xsl:value-of select="count($doc/value)"/>
      <br/>
      </body>
      </html>

      </xsl:template>
      </xsl:stylesheet>
      ---------------------------------------------------

      Now the output is correct:

      ---------------------------------------------------
      Number of elements: 2
      Number of elements: 2
      ---------------------------------------------------

      Comparing the two XSL files, the only diference is that the "doc" variable is declared outside or inside the template.

      Thank you!

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hander3@terra.com R
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: