PDA

View Full Version : QXmlQuery not transforming XSL



jwc
18th June 2009, 07:47
Hello all,

I am reasonably new to Python/QT and am having a few issues with transforming an XML file into HTML to be displayed in a QWebView by using an xsl file.

I am using QXmlQuery to take in the XML and XSL files but the problem I seem to be having is that it doesn't appear to produce a result when using .evaluateTo(). My peference is to pass through a generated XML string to the .setFocus() and then retrieve a string containing the HTML from the .evelauteTo(). But for testing I am just passing the XML file through from the file system.

I have attached my python/QT code as well as the XML/XSL doucments that may assist.

PyQT code:


dummyString = QString()

xmlQuery = QXmlQuery(QXmlQuery.XSLT20)
xmlQuery.setFocus(QUrl('../DATA/test.xml'))
xmlQuery.setQuery(QUrl('../DATA/test.xsl'))
xmlQuery.evaluateTo(dummyString)

print dummyString (nothing returned)


XML:


<?xml version="1.0" encoding="ISO-8859-1"?>
<Data>
<Survey_Data>
<Survey>
<SurveyId>1</SurveyId>
<ClientId>1</ClientId>
<MMOProviderId>1</MMOProviderId>
<SeismicContractorId>1</SeismicContractorId>
<SurveyName>North West Western Australia</SurveyName>
<Lease>North West Shelf</Lease>
<DEWHAReferralReferenceNumber></DEWHAReferralReferenceNumber>
<StartDate>2008-01-01</StartDate>
<EndDate>2008-01-19</EndDate>
<SourceFullPowerDuration></SourceFullPowerDuration>
<SourcePowerDownDistance></SourcePowerDownDistance>
<ShutDownDistance></ShutDownDistance>
<SourceVolume></SourceVolume>
<AirgunNumber></AirgunNumber>
<SPIntervalMetres></SPIntervalMetres>
<SPIntervalSeconds></SPIntervalSeconds>
<Notes></Notes>
<ClientName>Client 1</ClientName>
<MMOProviderName>MMO provider 1</MMOProviderName>
<SeismicContractorName>Seismic contractor 1</SeismicContractorName>
</Survey>
</Survey_Data>
</Data>


XSL:


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="data">
<html>
<body>
<h1>TEST</h1>
<table border="1">
<tr bgcolor="#343434">
<th>SurveyId</th>
<th>ClientName</th>
</tr>
<xsl:for-each select="Survey_Data/Survey">
<tr>
<td><xsl:value-of select="SurveyId"/></td>
<td><xsl:value-of select="ClientName"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Thank you.

Regards
James

jwc
24th June 2009, 01:26
Still no luck, can any one shed some light on what I may be doing wrong?

wysota
24th June 2009, 01:46
What is the output you receive? Did you make sure the data is loaded correctly?

jwc
24th June 2009, 07:03
There is no output at all, also no errors when opening the files from the file system.

How would you suggest debugging the QXmlQuery object to test to see if it is reading the XML and XSL files correctly?

Thank you for your response and assistance.

wysota
24th June 2009, 10:26
I would start by using QUrl::fromLocalFile()to make sure the URLs are correct and before that I would use QFile::exists() to see if the relative paths are correct.