Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74924

QXmlQuery xsl:variable in xsl:for-each wrong value

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 5.12.2
    • XML: QtXmlPatterns
    • None

    Description

      There exists a problem in the xslt-transformation with xsl:variable in xsl:for-each loops

      If you use a xsl:variable defined in an xsl:for-each only ONE time within the xsl:for-each it stores the correct value, if you use the variable multiple times it is always set to the value it gets in the first iteration of the xsl:for-each

      Example:

      a)

      <xsl:template match="/Module">
        <xsl:for-each select="Data">
          <xsl:variable name="Entry" select="@entry"/> 
          <xsl:value-of select="concat('value: ', $Entry, '&#x000A;')"/>
        </xsl:for-each>
      </xsl:template

      would output the expected value of the data for each iteration

      b)

      <xsl:template match="/Module">
        <xsl:for-each select="Data">
          <xsl:for-each select="Data"> 
            <xsl:variable name="Entry" select="@entry"/>
            <xsl:value-of select="concat('value: ', $Entry, '&#x000A;')"/>
            <xsl:value-of select="concat('value: ', $Entry, '&#x000A;')"/>  
        </xsl:for-each>
      </xsl:template>

      would output only the first iterations value of the variable

      Following example data:

      <Module>
       <Data entry="1"/>
       <Data entry="2"/>
       <Data entry="3"/>
      </Module>
      

      Output with QT5.12.2:

      a)

      value: 1
      value: 2
      value: 3

      b)

      value: 1
      value: 1
      value: 1
      value: 1
      value: 1
      value: 1

      while the correct output for b) should be

      value: 1
      value: 1
      value: 2
      value: 2
      value: 3
      value: 3

       

       

      I attached a sample xml , xslt and source that does a transformation. (simply adjust the path to the files)

      The output for the transformation with saxon, xalan and QT4.8.6 produces the correct result.

      Attachments

        1. main.cpp
          0.7 kB
        2. forvar.xml
          0.1 kB
        3. forvar.xslt
          0.7 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            cnn Qt Core & Network
            philipp_hrust Philipp Hrust
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes