[QT 4.7.4] [SOLVED] Generate an HTML from an XML with XSLT?
-
Hi,
I have an application that generates an XML file (that is the concatenation of QTestlib results enclosed in a private root element). I need, from this XML, to generate an HTML report. This report must be purely HTML (not an XML with an XSLT style sheet). I found a post explaining that I should do:
@ QXmlQuery query(QXmlQuery::XSLT20);
QString output;
query.setFocus(QUrl(xmlDir.canonicalPath() + "/" + fullFilename));
query.setQuery(QUrl("D:/dev/QTest/trunk/Data/unitarytest.xsl"));
query.evaluateTo(&output);@The QMxlQuery does something (I even have a warning because my XSLT is 1.0). But the result is an HTML page without the elements coming from the XML.
I found another post (on StackOverflow) from someone having the same problem that has solved it by giving a QString instead of the file name to the query. But it does not work in my case.
I did a try by putting manually the reference to the stylesheet in the XML and ask IE and Firefox to display me the result. Both display me the right things (but in Firefox display is strange).
Below my XSLT file:
@<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html xml:lang='fr' >
<head>
<title>Unitary test report</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
</head>
<body>
<h1>UNITARY TEST REPORT</h1>
<h2><xsl:value-of select="UnitaryTest/@date" /></h2>
<xsl:for-each select="UnitaryTest/TestCase">
<xsl:variable name="testname" select="@name" />
<h2 id="{$testname}.cpp"><xsl:value-of select="@name" />.cpp</h2>
<table border='2' CELLSPACING='0' CELLPADDING='8' >
<thead><TR><TH>FUNCTION</TH><TH>LINE</TH><TH>RESULT</TH><TH>NOTIFICATION</TH></TR></thead>
<tbody>
<xsl:for-each select="TestFunction">
<xsl:if test="@name != 'initTestCase' and @name != 'cleanupTestCase'">
<xsl:variable name="pass" select="Incident/@type" />
xsl:choose
<xsl:when test="$pass = 'pass'">
<TR><TD><xsl:value-of select="@name" /></TD><TD> -- </TD><TD>SUCCEEDED</TD><TD>OK</TD></TR>
</xsl:when><xsl:otherwise> <TR bgcolor="red"><TD><xsl:value-of select="@name" /></TD> <TD><xsl:value-of select="Incident/@line" /></TD> <TD>FAILED</TD> <TD><xsl:value-of select="Incident" /></TD></TR> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:for-each> </tbody> </table> </xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet> @And a sample part of the original XML file:
@<?xml version="1.0" encoding="ISO-8859-1"?>
<UnitaryTest date="mer. 5. juin 09:08:16 2013">
<TestCase name="UT_ApplicationCtrl">
<Environment>
<QtVersion>4.7.4</QtVersion>
<QTestVersion>4.7.4</QTestVersion>
</Environment>
<TestFunction name="initTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="unicity">
<Message type="qwarn" file="" line="0">
<Description><![CDATA[Object::connect: No such slot ApplicationWindow::slotSettings() in ....\source\GUI\ApplicationWindow.cpp:194]]></Description>
</Message>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="nextPreviousCtrl">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="disconnect">
<Incident type="fail" file="..\\..\\source\\UnitaryTest\\UT_ApplicationCtrl.cpp" line="161">
<Description><![CDATA['ApplicationWindow::getInstance()->m_previousButton->isVisible()' returned FALSE. (previous button visible)]]></Description>
</Incident>
</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
</TestCase>
<TestCase name="UT_Crypto">
<Environment>
<QtVersion>4.7.4</QtVersion>
<QTestVersion>4.7.4</QTestVersion>
</Environment>
<TestFunction name="initTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="testCrypto">
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>
</TestCase>
</UnitaryTest>@