Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT processing with Qt

Tags:

xslt

qt

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?

like image 949
swegi Avatar asked Mar 12 '10 13:03

swegi


1 Answers

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.

like image 193
Gabriel Alejandro López López Avatar answered Nov 09 '22 17:11

Gabriel Alejandro López López