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:
xmlQuery = QXmlQuery(QXmlQuery.XSLT20)
xmlQuery.
setFocus(QUrl('../DATA/test.xml'))xmlQuery.
setQuery(QUrl('../DATA/test.xsl'))xmlQuery.evaluateTo(dummyString)
print dummyString (nothing returned)
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)
To copy to clipboard, switch view to plain text mode
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>
<?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>
To copy to clipboard, switch view to plain text mode
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>
<?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>
To copy to clipboard, switch view to plain text mode
Thank you.
Regards
James
Bookmarks