title: XSLT: Unable to apply transformatio after nested node creation
body: <p>I am trying to create a nested set of nodes from the list of child elements, I am able to create the nested elements but not able to apply other transformations for the nested elements. I am still learning XSLT, kindly help me. Also, I am curious is there is an efficient way to convert child elements to nested element .
  (I have posted the code in the below location for testing.</p>
  
  <p><a href="https://xsltfiddle.liberty-development.net/93dFeq9" rel="nofollow noreferrer">https://xsltfiddle.liberty-development.net/93dFeq9</a></p>
  
  <p>)</p>
  
  <p><strong>Input XML:</strong></p>
  
  <pre><code>&lt;root&gt;
      &lt;person&gt;
          &lt;a/&gt;
          &lt;b/&gt;
          &lt;c/&gt;
          &lt;d/&gt;
      &lt;/person&gt;
  
      &lt;person&gt;
          &lt;a/&gt;
          &lt;b/&gt;
          &lt;c/&gt;
          &lt;d/&gt;
      &lt;/person&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><strong>XSLT:</strong> </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"  xmlns:mf="http://example.com/mf"&gt;
      &lt;xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /&gt;
  
  
      &lt;xsl:template match="@*|node()"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select="@*|node()"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="(a | b |c |d)"&gt;
          &lt;xsl:element name="{name()}"&gt;
              &lt;xsl:attribute name="type"&gt;alpha&lt;/xsl:attribute&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
  
      &lt;xsl:function name="mf:nest" as="node()*"&gt;
          &lt;xsl:param name="nodesl" as="node()*"/&gt;
          &lt;xsl:for-each-group select="$nodesl" group-adjacent="true()"&gt;
              &lt;xsl:copy select="."&gt;
                  &lt;xsl:sequence select="mf:nest(tail(current-group()))"/&gt;    
              &lt;/xsl:copy&gt;
  
          &lt;/xsl:for-each-group&gt;
      &lt;/xsl:function&gt;
  
      &lt;xsl:template match="person"&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:sequence select="mf:nest(*)"/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:transform&gt;
  </code></pre>
  
  <p><strong>Actual Output XML:</strong></p>
  
  <pre><code>&lt;root&gt;
      &lt;person&gt;
        &lt;a&gt;
           &lt;b&gt;
              &lt;c&gt;
                 &lt;d/&gt;
              &lt;/c&gt;
           &lt;/b&gt;
        &lt;/a&gt;
     &lt;/person&gt;
  
      &lt;person&gt;
        &lt;a&gt;
           &lt;b&gt;
              &lt;c&gt;
                 &lt;d/&gt;
              &lt;/c&gt;
           &lt;/b&gt;
        &lt;/a&gt;
     &lt;/person&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p><strong>Expected Output XML:</strong></p>
  
  <pre><code>&lt;root&gt;
      &lt;person&gt;
        &lt;a type="alpha"&gt;
           &lt;b type="alpha"&gt;
              &lt;c type="alpha"&gt;
                 &lt;d type="alpha"/&gt;
              &lt;/c&gt;
           &lt;/b&gt;
        &lt;/a&gt;
     &lt;/person&gt;
  
      &lt;person&gt;
        &lt;a type="alpha"&gt;
           &lt;b type="alpha"&gt;
              &lt;c type="alpha"&gt;
                 &lt;d type="alpha"/&gt;
              &lt;/c&gt;
           &lt;/b&gt;
        &lt;/a&gt;
     &lt;/person&gt;
  &lt;/root&gt;
  </code></pre>