title: document function in xslt
body: <p>I am triggering the transformation using a .NET4 code.</p>
  
  <p>the transformation works just fine, when I write the xpath with the document function directly in the xslt (see element PanelOK in the example xslt):
  </p>
  
  <p>but when the xPath itself is stored in a variable, it won't work (see element PanelException):</p>
  
  <pre><code>&lt;xsl:value-of select="@Customer"/&gt;
  </code></pre>
  
  <p>where @Customer has the value "document('myXml.xml')/COM:root/COM:Global/@Customer"</p>
  
  <p>Then I extended my xslt with a script. This works fine when I'm not using the document function in the xpath, e.g. only /COM:root/COM:Global/@Customer. But with the document function I get the exception <strong>XsltContext is needed for this query because of an unknown function.</strong></p>
  
  <p>Here are the examples: xml1 has the attribute customer with the value containing the xpath expression, xml2 is the file where the value can be found, xslt is the transformation which transforms xml1 and evaluates the xpath expression stored in the attribute customer which should look up the value in the xml2 using the custom script where the excpetion then in the select statement occurs. What must I do to get this working?</p>
  
  <p>xml1:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-16" standalone="no"?&gt;
  &lt;SFK:root xmlns:SFK="http://www.Test.com/SoftKeys"&gt;
    &lt;SFK:Panel Customer="document('setting.xml')/COM:root/COM:Global/@Customer"&gt;
    &lt;/SFK:Panel&gt;
  &lt;/SFK:root&gt;
  </code></pre>
  
  <p>xml2:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-16" standalone="no"?&gt;
  &lt;COM:root xmlns:COM="http://www.Test.com/Comm"&gt;
    &lt;COM:Global Customer="Microsoft"&gt;
    &lt;/COM:Global&gt;
  &lt;/COM:root&gt;
  </code></pre>
  
  <p>xslt:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                  xmlns:dyn="http://exslt.org/dynamic"
                  xmlns:SFK="http://www.Test.com/SoftKeys"
                  xmlns:COM="http://www.Test.com/Comm"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  extension-element-prefixes="dyn msxsl"
                  exclude-result-prefixes="msxsl xsl SFK COM dyn"&gt;
  
      &lt;!--Script to evaluate a string xPath to a Node. the real evaluate extension is not implemented in MS xslt processor--&gt;
      &lt;msxsl:script implements-prefix="dyn" language="C#"&gt;
          &lt;![CDATA[
              public XPathNodeIterator evaluate(XPathNavigator context, string expression)
              {
                  XmlNamespaceManager mngr = new XmlNamespaceManager(new NameTable());
                  mngr.AddNamespace("SFK","http://www.Test.com/SoftKeys");
                  mngr.AddNamespace("COM","http://www.Test.com/Comm");
                  mngr.AddNamespace("msxsl","urn:schemas-microsoft-com:xslt");
  
                  return context.Select(expression,mngr); // here occurs the exception
              }
          ]]&gt;
      &lt;/msxsl:script&gt;
  
      &lt;xsl:output method="xml" version="1.0"  encoding="UTF-8" indent="yes"/&gt;
      &lt;xsl:template match="/"&gt;
           &lt;xsl:apply-templates select="current()/SFK:root/SFK:Panel"/&gt;
      &lt;/xsl:template&gt;
      &lt;xsl:template match="SFK:Panel"&gt;
          &lt;/PanelOk&gt;
              &lt;xsl:value-of select="document('xml2.xml')/COM:root/COM:Global/@Customer"/&gt;
           &lt;/PanelOk&gt;
           &lt;/PanelException&gt;
              &lt;xsl:value-of select="dyn:evaluate(., @Customer)"/&gt;
           &lt;/PanelException&gt;     
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>