<?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="key" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: xsl:key</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: xsl:key"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>xsl:key</h1>
      <p>The <code>xsl:key</code> element is used at the top level of the stylesheet to declare an attribute, or other value,
that may be used as a key to identify nodes using the <code>key()</code> function within an expression. Each xsl:key
definition declares a named key, which must match the name of the key used in the <code>key()</code> function.</p>
      <p>The set of nodes to which the key applies is defined by a pattern in the match attribute: for example,
if <code>match="ACT|SCENE"</code> then every <code>ACT</code> element and every <code>SCENE</code> element is indexed by this key.</p>
      <p>The value of the key, for each of these matched elements, is determined by the <code>use</code> attribute.
This is an expression, which is evaluated for each matched element. If the expression returns a node-set,
the typed value of each node in this node-set acts as a key value. For example, if <code>use="AUTHOR"</code>, then each
AUTHOR child of the matched element supplies one key value. </p>
      <p>Note that:</p>
      <ol>
         <li content="para">
            <p>Keys are not unique: the same value may identify many different nodes</p>
         </li>
         <li content="para">
            <p>Keys are multi-valued: each matched node may have several (zero or more) values of the key, any one
of which may be used to locate that node</p>
         </li>
         <li content="para">
            <p>Keys can only be used to identify nodes within a single XML document: the key() function will return nodes
 that are in the same document as the current node.</p>
         </li>
      </ol>
      <p>All three attributes, <code>name</code>, <code>match</code>, and <code>use</code>, are mandatory.</p>
      <p>The optional <code>collation</code> attribute can be used when comparing strings.</p>
      <p>Saxon does not yet allow the <code>xsl:key</code> element to contain a sequence constructor in place
of the <code>use</code> attribute.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="matching-substring.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>