title: XSLT: regex extract and create nested nodes
body: <p>Of all my googling I can't seem to find how this can be done (plus I'm such a newb when it comes to xslt). I'm trying to take a flat sitemap.xml file and have nested children if the url path dictates.</p>
  <p>Sample sitemap</p>
  <pre><code>&lt;sitemap&gt;
  &lt;url&gt;
      &lt;loc&gt;https://example.com/&lt;/loc&gt;
      &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
      &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  &lt;url&gt;
      &lt;loc&gt;https://example.com/athletics/index.html&lt;/loc&gt;
      &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
      &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  &lt;url&gt;
      &lt;loc&gt;https://example.com/athletics/colleges-schools.html&lt;/loc&gt;
      &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
      &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  &lt;url&gt;
      &lt;loc&gt;https://example.com/training/index.html&lt;/loc&gt;
      &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
      &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  &lt;urls&gt;....&lt;/urls&gt;
  &lt;/sitemap&gt;
  </code></pre>
  <p>I either want to ultimately have it something like this</p>
  <pre><code>&lt;sitemap&gt;
  &lt;url&gt;
      &lt;loc&gt;https://example.com/&lt;/loc&gt;
      &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
      &lt;priority&gt;0.5&lt;/priority&gt;
      &lt;children&gt;
          &lt;url&gt;
              &lt;loc&gt;https://example.com/athletics/index.html&lt;/loc&gt;
              &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
              &lt;changefreq&gt;monthly&lt;/changefreq&gt;
              &lt;priority&gt;0.5&lt;/priority&gt;
              &lt;children&gt;
                  &lt;url&gt;
                      &lt;loc&gt;https://example.com/athletics/colleges-schools.html&lt;/loc&gt;
                      &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
                      &lt;changefreq&gt;monthly&lt;/changefreq&gt;
                      &lt;priority&gt;0.5&lt;/priority&gt;
                  &lt;/url&gt;
              &lt;/children&gt;
          &lt;/url&gt;
          &lt;url&gt;
              &lt;loc&gt;https://example.com/training/index.html&lt;/loc&gt;
              &lt;lastmod&gt;2022-02-28&lt;/lastmod&gt;
              &lt;changefreq&gt;monthly&lt;/changefreq&gt;
              &lt;priority&gt;0.5&lt;/priority&gt;
          &lt;/url&gt;
      &lt;/children&gt;
  &lt;/url&gt;
  &lt;/sitemap&gt;
  </code></pre>
  <p>or converted to a <code>.json</code>, but I have learned how to convert an xml to json quite easily, so I just really need to understand how I can regex (or something) into the <code>&lt;loc&gt;</code> field and generate children based of /XX_name_XX/</p>