<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="xsl-elements" page="evaluate" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: xsl:evaluate</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: xsl:evaluate"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>xsl:evaluate</h1>
      <p>The <code>xsl:evaluate</code> instruction is new in XSLT 3.0. It allows dynamic evaluation
of XPath expressions constructed as a string, in the same way as the <code>saxon:evaluate()</code>
extension function that has been available in Saxon for many years.</p>
      <p>The following example sorts product elements according to a sort key supplied (in the form of an XPath expression)
      as a parameter to the stylesheet.</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
            &lt;xsl:apply-templates select="product"&gt;
              &lt;xsl:sort&gt;
                &lt;xsl:evaluate select="$product-sort-key"/&gt;
              &lt;/xsl:sort&gt;
            &lt;/xsl:apply-templates&gt;           
      </code>
         </pre>
      </div>
      <p>The functionality is available as an XSLT instruction, rather than a function, to allow more
flexibility in the syntax, in particular the ability to define parameters using <code>xsl:with-param</code>
child elements.</p>
      <p>The instruction is fully implemented in Saxon 9.3 with the following exceptions:</p>
      <ul>
         <li content="para">
            <p>Functions available only in XSLT, such as key(), cannot be used in the target XPath expression.</p>
         </li>
      </ul>
      <p>The instruction may take an <code>xsl:fallback</code> to define fallback behaviour when using an
XSLT 2.0 processor.</p>
      <p>Attributes:</p>
      <ul>
         <li content="para">
            <p>xpath: an expression, which is evaluated to return the target expression as a string.</p>
         </li>
         <li content="para">
            <p>base-uri: a string (as an AVT), gives the base URI for the target expression. Defaults to the base
  URI of the stylesheet instruction.</p>
         </li>
         <li content="para">
            <p>namespace-context: an expression returning a node; the in-scope namespaces of this node define
  the namespace context for the XPath expression. Defaults to the namespace context of the <code>xsl:evaluate</code>
  instruction in the stylesheet</p>
         </li>
         <li content="para">
            <p>as: a SequenceType: defines the required type of the result of the XPath expression. Defaults to <code>item()*</code>
         </p>
         </li>
         <li content="para">
            <p>schema-aware: "yes" or "no", as an AVT: if "yes", the XPath expression has access to the schema components imported
  into the stylesheet.</p>
         </li>
      </ul>
      <p>Children:</p>
      <ul>
         <li content="para">
            <p>
            <code>xsl:with-param</code>: defines variables that the target expression can use.</p>
         </li>
         <li content="para">
            <p>
            <code>xsl:fallback</code>: defines fallback behaviour when using an
XSLT 2.0 (or 1.0) processor.</p>
         </li>
      </ul>
      <div class="boxed"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">Before using <code>xsl:evaluate</code>, consider whether higher-order functions (also new in XSLT 3.0) would
      provide a better solution to the problem. Also think carefully about the possibility of injection attacks if the
      expression to be evaluated is formed by string concatenation.</div>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="fallback.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>