title: How to Generate XML from Database
body: <p>I am fetching data from two tables CARRIER_IFTA ,IFTA_NAME.
   My Select Query is like below..</p>
  
  <pre><code>SELECT t1.IFTA_LICENSE_NUMBER,t1.IFTA_BASE_STATE,t2.NAME_TYPE,t2.NAME
  from CARRIER_IFTA t1 inner join  IFTA_NAME t2
      on t1.IFTA_LICENSE_NUMBER=t2.IFTA_LICENSE_NUMBER
  </code></pre>
  
  <p>My Data is coming in this way...</p>
  
  <pre><code>IFTA_LICENSE_NUMBER   IFTA_BASE_STATE  NAME_TYPE  NAME
  --------------------------------------------------------
  630908333                 US            LG        XYZ
  630908333                 US            MG        PQR
  730908344                 US            LG        ABC
  </code></pre>
  
  <p>Now using XSLT I want to generate XML like this </p>
  
  <pre><code>&lt;T0019&gt;
    &lt;IFTA_ACCOUNT&gt;
      &lt;IFTA_LICENSE_NUMBER&gt;630908333&lt;/IFTA_LICENSE_NUMBER&gt;
      &lt;IFTA_BASE_STATE&gt;US&lt;/IFTA_BASE_STATE&gt;
      &lt;IFTA_NAME&gt;
         &lt;NAME_TYPE&gt;LG&lt;NAME_TYPE&gt;
         &lt;NAME&gt;XYZ&lt;/NAME&gt;
      &lt;/IFTA_NAME&gt;
      &lt;IFTA_NAME&gt;
         &lt;NAME_TYPE&gt;MG&lt;NAME_TYPE&gt;
         &lt;NAME&gt;PQR&lt;/NAME&gt;
      &lt;IFTA_NAME&gt;
    &lt;/IFTA_ACCOUNT&gt;
    &lt;IFTA_ACCOUNT&gt;
       &lt;IFTA_LICENSE_NUMBER&gt;730908344&lt;/IFTA_LICENSE_NUMBER&gt;
       &lt;IFTA_BASE_STATE&gt;US&lt;/IFTA_BASE_STATE&gt;
       &lt;IFTA_NAME&gt;
         &lt;NAME_TYPE&gt;LG&lt;NAME_TYPE&gt;
         &lt;NAME&gt;ABC&lt;/NAME&gt;
      &lt;/IFTA_NAME&gt;
    &lt;/IFTA_ACCOUNT&gt;     
  
  &lt;/T0019&gt;
  </code></pre>
  
  <p>i have used below xslt but it is not giveng me desire result ...</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"&gt;
      &lt;xsl:template match="/ROWSET"&gt;
          &lt;xsl:element name="T0019"&gt;
              &lt;xsl:apply-templates select="IFTAACCOUNT"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
      &lt;xsl:template match="IFTAACCOUNT"&gt;
          &lt;xsl:element name="IFTAACCOUNT"&gt;
              &lt;xsl:apply-templates select="IFTA_CARRIER_ID_NUMBER"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
     &lt;xsl:template match="IFTA_LICENSE_NUMBER"&gt;
              &lt;xsl:element name="IFTA_LICENSE_NUMBER"&gt;
                  &lt;xsl:apply-templates /&gt;
              &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  
  &lt;xsl:template match="IFTA_BASE_STATE"&gt;
              &lt;xsl:element name="IFTA_BASE_STATE"&gt;
                  &lt;xsl:apply-templates /&gt;
              &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  &lt;xsl:template match="IRP_NAME"&gt;
       &lt;IRP_NAME&gt;
          &lt;xsl:apply-templates select="NAME"/&gt;    
          &lt;xsl:apply-templates select="NAME_TYPE"/&gt;       
       &lt;/IRP_NAME&gt;            
      &lt;/xsl:template&gt; 
  
      &lt;xsl:template match="NAME"&gt;
              &lt;xsl:element name="NAME"&gt;
                  &lt;xsl:value-of select="." /&gt;
              &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  
      &lt;xsl:template match="NAME_TYPE"&gt;
              &lt;xsl:element name="NAME_TYPE"&gt;
                  &lt;xsl:apply-templates /&gt;
              &lt;/xsl:element&gt;
      &lt;/xsl:template&gt; 
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>but it is not giving desire result ...</p>
  
  <p>Please help me ...</p>
  
  <p>Thanks in Advance...</p>