title: How to reference grouped elements in XSLT 2.0?
body: <p>I want to group the following XML file: </p>
  
  <pre><code>&lt;record&gt;
      &lt;word&gt;Hallo&lt;/word&gt;&lt;translit&gt;XUPPY&lt;/translit&gt;&lt;gloss&gt;gloss1&lt;/gloss&gt;
      &lt;word&gt;Bye&lt;/word&gt;&lt;translit&gt;EHS&lt;/translit&gt;&lt;gloss&gt;gloss2&lt;/gloss&gt;
      &lt;word&gt;Yes&lt;/word&gt;&lt;translit&gt;KGR&lt;/translit&gt;&lt;gloss&gt;gloss3&lt;/gloss&gt;
  &lt;/record&gt;
  </code></pre>
  
  <p>Desired output is</p>
  
  <pre><code>&lt;s&gt;
      &lt;set&gt;&lt;word&gt;Hallo&lt;/word&gt;&lt;gloss&gt;gloss1&lt;/gloss&gt;&lt;/set&gt;
      &lt;set&gt;&lt;word&gt;Bye&lt;/word&gt;&lt;gloss&gt;gloss2&lt;/gloss&gt;&lt;/set&gt;
      &lt;set&gt;&lt;word&gt;Yes&lt;/word&gt;&lt;gloss&gt;gloss3&lt;/gloss&gt;&lt;/set&gt;
  &lt;/s&gt;
  </code></pre>
  
  <p>So I use <code>for-each-group</code>, as in </p>
  
  <pre><code>&lt;xsl:template match="record"&gt;
      &lt;xsl:element name="s"&gt;
          &lt;xsl:for-each-group select="*" group-starting-with="word"&gt;
              &lt;xsl:element name = "set"&gt;
                  &lt;xsl:copy-of select="current-group()/word"/&gt;
                  &lt;xsl:copy-of select="current-group()/gloss"/&gt;
              &lt;/xsl:element&gt;
          &lt;/xsl:for-each-group&gt;
      &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>However, I get this output, i.e., empty groups: </p>
  
  <pre><code>&lt;s&gt;&lt;set/&gt;&lt;set/&gt;&lt;set/&gt;&lt;/s&gt; 
  </code></pre>
  
  <p>So I am doing something wrong while referencing the elements in the groups. But what? I am sure it must be something simple. </p>