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

XSL-T: Default namespace picked up by expressions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • Some future release
    • 4.5.0
    • XML: DOM
    • None

    Description

      test.xml
      --------
      <?xml version="1.0" encoding="UTF-8"?>
      <dishes>
      <dish>
      <name>Something</name>
      <description>Some description</description>
      </dish>
      </dishes>

      test.xsl
      --------
      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" indent="yes"/>
      <xsl:template match="/">
      <html>
      <body>
      <xsl:apply-templates/>
      </body>
      </html>
      </xsl:template>
      <xsl:template match="dish">
      <b>
      <xsl:value-of select="name"/>
      </b>
      </xsl:template>
      </xsl:stylesheet>

      test.cpp [snippet]
      ------------------
      QXmlQuery query(QXmlQuery::XSLT20);
      query.setFocus(QUrl("test.xml"));
      query.setQuery(QUrl("test.xsl"));
      QFile file("result.html");
      file.open(QIODevice::WriteOnly);
      QXmlFormatter formatter(query,&file);
      query.evaluateTo(&formatter);

      This code produces expected result:

      <html>
      <body>
      <b>Кирпичное ассорти</b>
      </body>
      </html>

      But once you change the stylesheet header to

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

      output becomes

      <html xmlns="http://www.w3.org/1999/xhtml">
      <body>
      Something
      Some description
      </body>
      </html>

      Looks like default templates are being used instead of the provided one for
      the dish node. Browsers with XSLT support process this example without
      problems,
      however. Duplicating namespace declaration on root elements of all templates
      instead of specifying it on the stylesheet header works, but is not a good
      solution.

      ---------------------------
      In short, this:

      <xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/1999/xhtml">

      <xsl:template match="dish">
      <xsl:sequence select="'result'"/>
      </xsl:template>

      </xsl:stylesheet>

      will match

      {http://www.w3.org/1999/xhtml}

      dish, not {}dish. The attribute xpath-default-namespace plays in here(unsupported in 4.5).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            fenglich Frans Englich (closed Nokia identity)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes