[Qt-interest] Default namespace in XSLT stylesheet

Paul Lebedev paul.lebedev at gmail.com
Mon Mar 9 15:06:31 CET 2009


Hi, I've been trying to use new XSLT functionality in Qt 4.5 final,
but can't get default namespaces in stylesheets working.

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.

Is this a problem with the preview XSLT functionality in Qt or am I doing
anything wrong?





More information about the Qt-interest-old mailing list