<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensions" page="functions" subpage="expression"/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: saxon:expression()</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: saxon:expression()"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>saxon:expression()</h1>
      <p><b>saxon:expression($expr as xs:string) ==&gt; jt:net.sf.saxon.functions.Evaluate-PreparedExpression</b></p>
      <p><b>saxon:expression($expr as xs:string, $ns as element()) ==&gt; jt:net.sf.saxon.functions.Evaluate-PreparedExpression</b></p>
      <p>This function creates a stored expression that can be evaluated repeatedly with different
argument values and a different dynamic context.</p>
      <p>The supplied string must contain an XPath expression. The result of the function is a <i>stored
expression</i>, which may be supplied as an argument to other extension functions such as
<a class="bodylink" href="../../extensions/functions/eval.xml">saxon:eval</a>. The result of
the expression will usually depend on the current node. The context for the expression includes the namespaces in scope at this point in the
stylesheet. The expression may contain references to the nine variables <code>$p1</code>, <code>$p2</code>, ...
 <code>$p9</code> only. It may contain calls on Java extension functions, including Saxon and EXSLT-defined
 functions, as well as user-defined function declared within the containing query or stylesheet. 
 But it does not allow access to stylesheet variables, or 
 functions defined in the XSLT specification such as <code>key()</code> or <code>format-number()</code>.</p>
      <p><i>Use of the <code>current()</code> function is allowed, provided <code>saxon:evaluate()</code> is called
 from XSLT: the value is the context item at the point where <code>saxon:evaluate()</code> or <code>saxon:eval()</code>
 is called. Use of other XSLT-specific functions such as <code>key()</code> or <code>format-number()</code> is
 untested; they might work in some cases and fail in others, possibly in an obscure way.</i></p>
      <p>If the second argument is present, its value must be a single element node. The in-scope namespace bindings 
 of this element node be used to resolve any namespace prefixes present in the XPath expression. The default
 namespace for the element is also used as the default namespace for elements and types within the XPath expression.
 In addition, standard namespace bindings are automatically available for the prefixes xml, xs, xsi, fn, and saxon.</p>
      <p>If the second argument is omitted, then the namespace context for the expression is taken from the
 stylesheet. (This is also the rule used by <code>saxon:evaluate()</code>.) 
If the expression contains namespace prefixes, these are interpreted
in terms of the namespace declarations in scope at the point where the 
<code>saxon:expression()</code> function is
called, not those in scope where the stored expression is evaluated.</p>
      <p>The stored expression (if it is to be evaluated using <code>saxon:eval()</code>) may contain
references to variables named <code>$p1</code>, <code>$p2</code>, ... <code>$p9</code>. The values of
these variables can be supplied when the expression is evaluated using <code>saxon:eval</code>. The
second argument of <code>saxon:eval</code> supplies the value of <code>$p1</code>, the third
argument supplies the value of <code>$p2</code>, and so on.</p>
      <p>For example, following <code>&lt;xsl:variable name="add" select="saxon:expression('$p1 + $p2')"/&gt;</code>,
the instruction <code>&lt;xsl:value-of select="saxon:eval($add, 6, 7)"/&gt;</code> will output <code>13</code>.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="find.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>