<?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="for-each-group" subpage=""/>
      <!--
           Generated at 2010-10-29T18:20:48.427+01:00--><title>Saxonica: XSLT and XQuery Processing: xsl:for-each-group</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: xsl:for-each-group"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>xsl:for-each-group</h1>
      <p>The <code>xsl:for-each-group</code> element selects a sequence of nodes and/or atomic
values and organizes them into subsets called groups. There are four possible ways of defining the
grouping:</p>
      <ul>
         <li content="para">
            <p>
            <b>group-by:</b> This groups together all items having the same value for a grouping key.
The grouping key may have multiple values (a sequence of values) in which case the item is added
to more than one group.</p>
         </li>
         <li content="para">
            <p>
            <b>group-adjacent:</b> This groups together all items having the same value for a grouping key,
provided that they are also adjacent in the input sequence. This is useful when you need to wrap a
new element around a sequence of related elements in the source documents, for example a consecutive
sequence of <code>&lt;bullet&gt;</code> elements. In this case the grouping key must be single-valued.</p>
         </li>
         <li content="para">
            <p>
            <b>group-starting-with:</b> This processes the items in the supplied sequence in turn, starting
a new group whenever one of the items matches a specified pattern. This is useful, for example,
when matching an <code>&lt;h2&gt;</code> element and its following <code>&lt;p&gt;</code>
elements.</p>
         </li>
         <li content="para">
            <p>
            <b>group-ending-with:</b> This processes the items in the supplied sequence in turn, closing
the current group whenever one of the items matches a specified pattern. This is useful
when matching a sequence of items in which the last item in the group carries some distinguishing
attribute such as <code>continued="no"</code>.</p>
         </li>
      </ul>
      <p>Saxon implements the <code>xsl:for-each-group</code> instruction in full, except that some error
conditions are not detected. For examples of using the instruction, see 
<a href="http://www.w3.org/TR/xslt20/#grouping" class="bodylink">the draft XSLT 2.0 specification</a>.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="function.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>