title: How to transform a XML document with metadata using XSLT?
body: <p>I have a report generator tool that produces XML documents for different kinds of reports. Each of those XML documents will have a set of fields (reporting:columns in the below XML document) which are used to describe the actual data (reporting:line in the below XML document) in it. Since the list of fields is dynamic and keep changing for every kind of report, how to write a generic XSL template that use the 'fields' to transform the data into a csv file. </p>
  
  <p>My sample XML document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no" ?&gt;
  &lt;reporting:root xmlns:reporting="http://www.something.net/reporting"&gt;
  
    &lt;reporting:default0 reporting:type="Portfolio"&gt;
      &lt;reporting:header&gt;      
        &lt;reporting:configuration&gt;
          &lt;reporting:columns&gt;
            &lt;reporting:column reporting:group="instrument" reporting:name="Ident" reporting:tag="ident" reporting:type="int"/&gt;
            &lt;reporting:column reporting:group="prices" reporting:name="Last (Time)" reporting:tag="lastTime" reporting:type="string"/&gt;
            &lt;reporting:column reporting:group="noGroup" reporting:name="RIC" reporting:tag="ric" reporting:type="string"/&gt;
            &lt;reporting:column reporting:group="instrument" reporting:name="Reference" reporting:tag="reference" reporting:type="string"/&gt;
           &lt;reporting:column reporting:group="result" reporting:name="Currency" reporting:tag="currency" reporting:type="string"/&gt;          
          &lt;/reporting:columns&gt;
       &lt;/reporting:configuration&gt;      
      &lt;/reporting:header&gt;
      &lt;reporting:window reporting:Id="36674" reporting:level="0" reporting:name="MY_PORTFOLIO" reporting:parentId="11991"&gt;
        &lt;reporting:line reporting:Id="67520135" reporting:level="1" reporting:name="INTERNATIONAL BUSINESS MACHINES CORP" reporting:parentId="36674" reporting:positionType="0"&gt;
          &lt;reporting:ident&gt;643633&lt;/reporting:ident&gt;        
          &lt;reporting:reference&gt;IBM.USD&lt;/reporting:reference&gt;
          &lt;reporting:currency&gt;USD&lt;/reporting:currency&gt;        
        &lt;/reporting:line&gt;
       &lt;reporting:line reporting:Id="67520179" reporting:level="1" reporting:name="GENERAL ELECTRIC CO" reporting:parentId="36674" reporting:positionType="0"&gt;
          &lt;reporting:ident&gt;643635&lt;/reporting:ident&gt;
          &lt;reporting:ric&gt;GE.N&lt;/reporting:ric&gt;
          &lt;reporting:reference&gt;GE.USD&lt;/reporting:reference&gt;
          &lt;reporting:currency&gt;USD&lt;/reporting:currency&gt;        
       &lt;/reporting:line&gt;
      &lt;/reporting:window&gt;
    &lt;/reporting:default0&gt;
  &lt;/reporting:root&gt;
  </code></pre>
  
  <p>I need to see the output formated like:</p>
  
  <pre><code>ident,lastTime,ric,reference,currency
  643633,,,IBM.USD,USD
  643635,,GE.N,GE.USD,USD
  </code></pre>
  
  <p>I did some work on it but it was half way through. Could not find how the handle the 'dynamic' list of fields and use them as tags that describe the actual data.</p>
  
  <p>Can somebody help ?</p>
  
  <p>Thanks.</p>