title: How to WRAP the elements in XSLT using for-each-group?
body: <p>I want to Wrap <strong>value5 to value7</strong> in a single node call <strong>COUNTRY</strong> using <strong>XSLT</strong></p>
  
  <p><strong>Example XML Document</strong>-</p>
  
  <pre><code>&lt;root&gt;
    &lt;root1&gt;
      &lt;root2&gt;
       &lt;value1&gt;somevalue&lt;/value1&gt;
       &lt;value2&gt;somevalue&lt;/value2&gt;
       &lt;value3&gt;somevalue&lt;/value3&gt;
       &lt;value4&gt;somevalue&lt;/value4&gt;
       &lt;value5&gt;Australia&lt;/value5&gt;
       &lt;value6&gt;India&lt;/value6&gt;
       &lt;value7&gt;USA&lt;/value7&gt;
       &lt;value8&gt;somevalue&lt;/value8&gt;
       &lt;value9&gt;somevalue&lt;/value9&gt;
       &lt;value10&gt;somevalue&lt;/value10&gt;
     &lt;/root2&gt;
    &lt;/root1&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><strong>Output XML</strong>-</p>
  
  <pre><code>&lt;root&gt;
    &lt;root1&gt;
      &lt;root2&gt;
       &lt;value1&gt;somevalue&lt;/value1&gt;
       &lt;value2&gt;somevalue&lt;/value2&gt;
       &lt;value3&gt;somevalue&lt;/value3&gt;
       &lt;value4&gt;somevalue&lt;/value4&gt;
       &lt;COUNTRY&gt;
         &lt;value5&gt;Australia&lt;/value5&gt;
         &lt;value6&gt;India&lt;/value6&gt;
         &lt;value7&gt;USA&lt;/value7&gt;
       &lt;/COUNTRY&gt;
       &lt;value8&gt;somevalue&lt;/value8&gt;
       &lt;value9&gt;somevalue&lt;/value9&gt;
       &lt;value10&gt;somevalue&lt;/value10&gt;
     &lt;/root2&gt;
    &lt;/root1&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><strong>Code i am using currently</strong>-</p>
  
  <pre><code>xquery version "1.0-ml";
  declare variable $doc := document {
   &lt;root&gt;
    &lt;root1&gt;
      &lt;root2&gt;
       &lt;value1&gt;somevalue&lt;/value1&gt;
       &lt;value2&gt;somevalue&lt;/value2&gt;
       &lt;value3&gt;somevalue&lt;/value3&gt;
       &lt;value4&gt;somevalue&lt;/value4&gt;
       &lt;value5&gt;Australia&lt;/value5&gt;
       &lt;value6&gt;India&lt;/value6&gt;
       &lt;value7&gt;USA&lt;/value7&gt;
       &lt;value8&gt;somevalue&lt;/value8&gt;
       &lt;value9&gt;somevalue&lt;/value9&gt;
       &lt;value10&gt;somevalue&lt;/value10&gt;
     &lt;/root2&gt;
    &lt;/root1&gt;
  &lt;/root&gt;
  };
  
  declare variable $grouping-xslt := &lt;xsl:stylesheet version="2.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output omit-xml-declaration="yes" indent="yes" /&gt;
  
  &lt;xsl:template match="root"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:for-each-group select="*" group-adjacent="not(self::value5 | self::value6 | self::value7)"&gt;
              &lt;xsl:choose&gt;
                  &lt;xsl:when test="current-grouping-key()"&gt;
                      &lt;xsl:copy-of select="current-group()"/&gt;
                  &lt;/xsl:when&gt;
                  &lt;xsl:otherwise&gt;
                      &lt;country&gt;
                          &lt;xsl:copy-of select="current-group()"/&gt;
                      &lt;/country&gt;
                  &lt;/xsl:otherwise&gt;
              &lt;/xsl:choose&gt;
          &lt;/xsl:for-each-group&gt;        
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;;
  
  xdmp:xslt-eval($grouping-xslt, $doc)
  </code></pre>
  
  <p>I am having some issues while forming template with respect to <code>root</code>.</p>
  
  <p>Any Suggestions?</p>