title: XML- Denormalizing repeating siblings
body: <p>We send out target files to vendors and they can contain 0-30 optional fields.  Our XSD works to transfer to normalized DB but it isn't so good for a low tech print vendor.  So I wanted to use an XSLT to create a denormalized view of the data that even a basic user could decode with Excel.  The trick is not every record has the same or same number optional fields and I don't know how to align this to work.</p>
  
  <pre><code>&lt;target&gt;
          &lt;transactionNumber&gt;536880912&lt;/transactionNumber&gt;
         &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;PROMO_CODE&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;ABC127&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
          &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;Version&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;CON&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
          &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;cell&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;2&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
    &lt;/target&gt;
    &lt;target&gt;
          &lt;transactionNumber&gt;536880924&lt;/transactionNumber&gt;
          &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;PROMO_CODE&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;ABC131&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
          &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;Version&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;CON&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
    &lt;/target&gt;
  &lt;target&gt;
          &lt;transactionNumber&gt;536880213&lt;/transactionNumber&gt;
          &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;Version&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;CON&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
          &lt;optionalField&gt;
              &lt;optionalFieldLabel&gt;cell&lt;/optionalFieldLabel&gt;
              &lt;optionalFieldDescription&gt;1&lt;/optionalFieldDescription&gt;
          &lt;/optionalField&gt;
    &lt;/target&gt;
  </code></pre>
  
  <p>I'm new here so no images :(</p>
  
  <p>I'm trying for something like this:</p>
  
  <p>536880912___PROMO_CODE___ABC127___Version___CON___cell___2</p>
  
  <p>536880924___PROMO_CODE___ABC131___Version___CON  </p>
  
  <p>536880213_____________________________Version___CON___cell___1</p>
  
  <p>Or an HTML table where my optionalfieldlabel is the header of each column.</p>
  
  <p><strong>I just came to the realization how to simplify my problem.</strong>
  Basically I just need strip out the optionfield and optionalfieldlabel tags and replace them with the with a new tag using the optionalfieldlabel value.  So it transforms to look like this:</p>
  
  <pre><code>&lt;target&gt;
          &lt;transactionNumber&gt;536880912&lt;/transactionNumber&gt;
         &lt;PROMO_CODE&gt;
              &lt;optionalFieldDescription&gt;ABC127&lt;/optionalFieldDescription&gt;
          &lt;/PROMO_CODE&gt;
          &lt;Version&gt;
              &lt;optionalFieldDescription&gt;CON&lt;/optionalFieldDescription&gt;
          &lt;/Version&gt;
          &lt;cell&gt;
              &lt;optionalFieldDescription&gt;2&lt;/optionalFieldDescription&gt;
          &lt;/cell&gt;
    &lt;/target&gt;
    &lt;target&gt;
          &lt;transactionNumber&gt;536880924&lt;/transactionNumber&gt;
          &lt;PROMO_CODE&gt;
              &lt;optionalFieldDescription&gt;ABC131&lt;/optionalFieldDescription&gt;
          &lt;/PROMO_CODE&gt;
          &lt;Version&gt;
              &lt;optionalFieldDescription&gt;CON&lt;/optionalFieldDescription&gt;
          &lt;/Version&gt;
    &lt;/target&gt;
  &lt;target&gt;
          &lt;transactionNumber&gt;536880912&lt;/transactionNumber&gt;
          &lt;Version&gt;
              &lt;optionalFieldDescription&gt;CON&lt;/optionalFieldDescription&gt;
          &lt;/Version&gt;
          &lt;cell&gt;
              &lt;optionalFieldDescription&gt;1&lt;/optionalFieldDescription&gt;
          &lt;/cell&gt;
    &lt;/target&gt;
  </code></pre>
  
  <p>Thanks in advance. </p>