<?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html> <head> <this-is section="expressions" page="xpath30new" subpage=""/> <!-- Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: New features in XPath 3.0</title> <meta name="coverage" content="Worldwide"/> <meta name="copyright" content="Copyright Saxonica Ltd"/> <meta name="title" content="Saxonica: XSLT and XQuery Processing: New features in XPath 3.0"/> <meta name="robots" content="noindex,nofollow"/> <link rel="stylesheet" href="../saxondocs.css" type="text/css"/> </head> <body class="main"> <h1>New features in XPath 3.0</h1> <div class="boxed" style="border: solid thin; background-color: #B1CCC7; padding: 2px">These features are available in Saxon only if explicitly enabled, either directly, or by requesting support for XSLT 3.0 or XQuery 3.0. In both cases, this requires Saxon-PE or above.</div> <p>Some of the new features in XPath 3.0 are as follows. For full details, see the W3C specifications.</p> <ol> <li> <p>The concatenation operator <code>||</code> is available (as in SQL). For example, <code>('$' || 12.5)</code> returns the string '$12.5'.</p> </li> <li> <p>A new simple mapping operator is available, <code>!</code>. This works rather like <code>/</code>, except there is no restriction that the left hand operand must be a node-set, and there is no sorting of results into document order. For example, <code>(1 to 7)!(.*.)</code> returns the sequence <code>(1, 4, 9, 16, 25, 36, 49)</code>.</p> </li> <li> <p>Local variables can be declared in a <code>let</code> expression, for example <code>let $x := /*/@version return //e[@version = $x]</code></p> </li> <li> <p>Inline function items can be declared, and used as arguments to higher-order functions. For example <code>map(//employee, function($e){$e/salary + $e/bonus})</code>. A <i>function item</i> is a third kind of item, alongside nodes and atomic values. The function represented by a function item <code>$f</code> can be invoked using a dynamic function call <code>$f(args)</code>.</p> </li> <li> <p>Maps are available (for more details see <a class="bodylink" href="../expressions/xpath30maps.xml">Maps</a>. They provide a similar capability to "objects" in Javascript, or "associative arrays" in some other languages. But as befits a function language like XPath, they are immutable. A collection of functions is available to operate on maps (see <a class="bodylink" href="../functions/intro.xml">XSLT 2.0 and XPath 2.0 Functions</a>), and in addition there is new syntax for a map constructor (of the form <code>map{ key := value, key := value }</code> where both the keys and values are arbitrary expressions. There is a sequenceType for maps: <code>map(K, V)</code> defining the types of the key and value parts. Maps are functions, so given a map $M, the entry for a key $K can be obtained as the result of the function call <code>$M($K)</code>.</p> </li> <li> <p>Expanded QNames can be written in the notation <code>"uri":local</code>, allowing XPath expressions to be written that do not depend on an externally-supplied namespace context.</p> </li> </ol> <p>A number of new functions are available, including <code>head</code>, <code>tail</code>, <code>map</code>, <code>filter</code>, <code>map-pairs</code>, <code>pi</code>, <code>sin</code>, <code>cos</code>, <code>tan</code>, <code>asin</code>, <code>acos</code>, <code>atan</code>, <code>sqrt</code>, <code>format-integer</code>, and others. For details see <a class="bodylink" href="../functions/intro.xml">XSLT 2.0 and XPath 2.0 Functions</a>.</p> <table width="100%"> <tr> <td> <p align="right"><a class="nav" href="xpath30maps.xml">Next</a></p> </td> </tr> </table> </body> </html>