5
votes

I like to display some (X)HTML content in a Qt application using QtWebKit. The content should be generated from XML documents via XSLT.

As I am new to Qt, my questions are as follows:
1) Can QtWebKit display XML documents with the xml-stylesheet element set?
2) Can Qt apply XSLT to an XML document and return the result as a string or write it to a file?

2

2 Answers

13
votes

With QXmlQuery you can process a XML document against a XSL template and then pass the result to the QWebView::setHtml(QString) (recent versions of Qt will use QWebEngineView::setHtml(..).

QString out;
QXmlQuery query(QXmlQuery::XSLT20);
query.setFocus(QUrl("myInput.xml"));
query.setQuery(QUrl("myStylesheet.xsl"));
query.evaluateTo(&out);
webview->setHtml(out);

You can find this code and more information in the QXmlQuery documentation.

0
votes

QtWebKit and xslt were always seprate, combining them was always a todo - not sure what the current status is but you can easily test it with the examples.

Or follow http://labs.trolltech.com/blogs/2010/03/03/qtwebkit-releases/