title: XQSharp XSLT2 performance tuning
body: <p>I have a real time application that uses XSLT1 and i want to upgrade to XSLT2.
  Currently i am using microsoft xslt1 engine that performs for a specific xml and xsl within 0.1 second. </p>
  
  <p>For XSLT2 transformation i created a function that uses XQSharp to perform xslt2 transformation. I used the same xml and xsl and the transformation took 0.9 second.</p>
  
  <p>I analyzed my code and it turns out that more then 90% of the processing time is caused by this line :</p>
  
  <blockquote>
    <p>Dim query As Xslt = Xslt.Compile(New StringReader(inputXsl), querySettings)</p>
  </blockquote>
  
  <p>My question is of there is a way to speed up this process ?</p>
  
  <p>For example by changing some querySettings? </p>
  
  <p>My full code</p>
  
  <pre class="lang-vb prettyprint-override"><code>   &lt;WebMethod()&gt; _
      Public Function XSLTXQSharp(ByVal inputXml As String, ByVal inputXsl As String) As String
          Dim nameTable As XmlNameTable = New NameTable()
  
          Dim xmlReaderSettings As New XmlReaderSettings()
          xmlReaderSettings.NameTable = nameTable
  
          Dim document As XdmDocument
  
          Using reader As New StringReader(inputXml)
              Using xmlReader As XmlReader = xmlReader.Create(reader, xmlReaderSettings)
                  document = New XdmDocument(xmlReader)
              End Using
          End Using
  
  
          Dim querySettings As New XsltSettings(nameTable)
          querySettings.ContextItemType = XdmType.Node
          querySettings.ModuleResolver = New XmlUrlResolver()
  
  
          ''' SLOW!!! more then 90 % of execution time
          Dim query As Xslt = Xslt.Compile(New StringReader(inputXsl), querySettings)
  
          Dim contextItem As XPathNavigator = document.CreateNavigator()
          Dim result As Stream = New MemoryStream()
          query.ApplyTemplates(contextItem, result)
  
          'Return dt2.Subtract(dt1).ToString()
  
          result.Position = 0
          Using reader As StreamReader = New StreamReader(result)
              Return reader.ReadToEnd()
          End Using
  
  
      End Function
  </code></pre>