title: QXmlQuery - passing parameter to XSLT
body: <p>Sample XSLT</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="html" indent="yes" encoding="UTF-8"/&gt;
  &lt;xsl:param name="my-param" select="'none'"/&gt;
  
  &lt;xsl:template match="sample"&gt;
    &lt;html&gt;&lt;body&gt;&lt;p&gt;
      parameter: &lt;xsl:value-of select="$my-param"/&gt;
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>Sample XML:
      </p>
  
  <pre><code>&lt;sample/&gt;
  </code></pre>
  
  <p>Using <code>xmlpatterns</code> like so:</p>
  
  <pre><code>xmlpatterns sample.xsl sample.xml -param my-param=funky
  </code></pre>
  
  <p>I can make the HTML output read:</p>
  
  <pre><code>&lt;html&gt;&lt;body&gt;&lt;p&gt;
     parameter: funky&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Brilliant!</p>
  
  <p>Q: How do I pass <code>my-param</code> to my XSLT using QXmlQuery?</p>
  
  <p>I suspect it must be one of the <code>bindVariable()</code> overloads, but none seem a match for a simple string parameter.</p>
  
  <p>Additional information in case it matters:
  We are still using <a href="http://qt.apidoc.info/4.7.4/qxmlquery.html" rel="nofollow noreferrer">Qt4.7</a> at work.
  But having had a quick look on the internet, the public interface for QXmlQuery seems no different in <a href="http://doc.qt.io/qt-5/qxmlquery.html" rel="nofollow noreferrer">Qt 5.x</a></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>What I have so far:</p>
  
  <pre><code>QString output;
  
  QXmlQuery query(QXmlQuery::XSLT20);
  query.setFocus(QUrl(input_xml));
  query.setQuery(QUrl::fromLocalFile(":/sample.xsl"));
  query.evaluateTo(&amp;output);
  </code></pre>
  
  <p>I use <code>QXmlQuery::XSLT20</code> because it gives me the least headaches even though my XSLT is targeted at version 1.0 (just in case this has you confused)</p>