title: Wrap multiple optional XML elements into a new wrapper XML element using XSLT
body: <p>I have an XML file which looks like the following:</p>
  
  <pre><code>&lt;a&gt;
    ......
    &lt;b&gt;
      &lt;c&gt;
        &lt;c1&gt;some text&lt;/c1&gt;
      &lt;/c&gt;
      &lt;d&gt;
        &lt;d1&gt;some more text&lt;/d1&gt;
        &lt;d1&gt;even more text&lt;/d1&gt;
      &lt;/d&gt;
      &lt;e&gt;
        &lt;e1&gt;some more text&lt;/e1&gt;
        &lt;e1&gt;even more text&lt;/e1&gt;
      &lt;/e&gt;
    &lt;/b&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>And I want to wrap elements <code>&lt;d&gt;</code> and <code>&lt;e&gt;</code> into a <code>&lt;wrapper&gt;</code> element, so I can have something like the following:</p>
  
  <pre><code>&lt;a&gt;
    ......
    &lt;b&gt;
      &lt;c&gt;
        &lt;c1&gt;some text&lt;/c1&gt;
      &lt;/c&gt;
      &lt;wrapper&gt;
        &lt;d&gt;
          &lt;d1&gt;some more text&lt;/d1&gt;
          &lt;d1&gt;even more text&lt;/d1&gt;
        &lt;/d&gt;
        &lt;e&gt;
          &lt;e1&gt;some more text&lt;/e1&gt;
          &lt;e1&gt;even more text&lt;/e1&gt;
          &lt;e2&gt;even more&lt;/e2&gt;
        &lt;/e&gt;
      &lt;/wrapper&gt;
    &lt;/b&gt;
    ......
  &lt;/a&gt;
  </code></pre>
  
  <p>One of the problems that I'm facing (apart from the fact that I'm new to XSLT) is that both <code>&lt;d&gt;</code> and <code>&lt;e&gt;</code> are optional.</p>
  
  <p>How can I do this?</p>