title: How to arrange and group elemets by using predefined rule?
body: <p>Good day!</p>
  
  <p>I'm trying to build up an xsl transformation file that do the next: </p>
  
  <p>There is an element that has a bunch of child elements of the type Characteristic. Each of them has its unique Name. 
  I also have a list that describes the logical connection between some of Names and a certain named Characteristic sets (called Datasets):</p>
  
  <p>CharacteristicName    :   DatasetName  <br/>
  &minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;&minus;<br/>
  Att1_DS1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;DS1<br/>
  Att2_DS1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;DS1<br/>
  Att1_DS2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;DS2<br/>
  Att2_DS2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;DS2</p>
  
  <p>I have to transform the xml so the main element should get new elements of type <code>&lt;Dataset&gt;</code>. These Dataset with ids from the table should appear if the listed Characteristic Names appear in the source document. And then the corresponding Characteristics are copyed to these Dataset elements/</p>
  
  <p>If some Characteristic Name  is not listed in the table so it should be placed in the Dataset with the id "Other"</p>
  
  <p>Source XML:</p>
  
  <pre><code>&lt;Object&gt;
      &lt;ID&gt;Obj1&lt;/ID&gt;
  
      &lt;!--DS1--&gt;     
      &lt;Characteristic&gt;
          &lt;Name&gt;Att1_DS1&lt;/Name&gt;
          &lt;Value&gt;25&lt;/Value&gt;
      &lt;/Characteristic&gt;
  
      &lt;!--DS2--&gt;
      &lt;Characteristic&gt;
          &lt;Name&gt;Att1_DS2&lt;/Name&gt;
          &lt;Value&gt;25&lt;/Value&gt;
      &lt;/Characteristic&gt;
  
      &lt;!--DS1--&gt;  
      &lt;Characteristic&gt;
          &lt;Name&gt;Att2_DS1&lt;/Name&gt;
          &lt;Value&gt;ABC&lt;/Value&gt;
      &lt;/Characteristic&gt;       
  
      &lt;!--DS2--&gt;
      &lt;Characteristic&gt;
          &lt;Name&gt;Att2_DS2&lt;/Name&gt;
          &lt;Value&gt;ABC&lt;/Value&gt;
      &lt;/Characteristic&gt;   
  
              &lt;!--Other--&gt;
      &lt;Characteristic&gt;
          &lt;Name&gt;Att3_NN&lt;/Name&gt;
          &lt;Value&gt;25&lt;/Value&gt;
      &lt;/Characteristic&gt;   
  
  &lt;/Object&gt;
  </code></pre>
  
  <p>It should be transformed to:</p>
  
  <pre><code>&lt;Object&gt;
      &lt;ID&gt;Obj1&lt;/ID&gt;
  
      &lt;Dataset id="DS1"&gt;
          &lt;Characteristic&gt;
              &lt;Name&gt;Att1_DS1&lt;/Name&gt;
              &lt;Value&gt;25&lt;/Value&gt;
          &lt;/Characteristic&gt;
          &lt;Characteristic&gt;
              &lt;Name&gt;Att2_DS1&lt;/Name&gt;
              &lt;Value&gt;ABC&lt;/Value&gt;
          &lt;/Characteristic&gt;
      &lt;/Dataset&gt;
  
      &lt;Dataset id="DS2"&gt;
          &lt;Characteristic&gt;
              &lt;Name&gt;Att1_DS1&lt;/Name&gt;
              &lt;Value&gt;25&lt;/Value&gt;
          &lt;/Characteristic&gt;
          &lt;Characteristic&gt;
              &lt;Name&gt;Att2_DS1&lt;/Name&gt;
              &lt;Value&gt;ABC&lt;/Value&gt;
          &lt;/Characteristic&gt;
      &lt;/Dataset&gt;
  
      &lt;Dataset id="Other"&gt;
          &lt;Characteristic&gt;
              &lt;Name&gt;Att3_NN&lt;/Name&gt;
              &lt;Value&gt;25&lt;/Value&gt;
          &lt;/Characteristic&gt;
      &lt;/Dataset&gt;
  
  &lt;/Object&gt;
  </code></pre>
  
  <p>Could you please help me doing these. Any tips or ideas which direction should I move?</p>