1 Reply Latest reply on Jun 14, 2019 9:26 AM by Martien van den Akker

    Creating multiple rows from one record in xslt


      Dear All,


      I need to fetch one csv file which is currently having one record. I am using soa suite file adapter to pull record and pushing to DB table(with multiple rows).



      <part  name="body">


         <RECORD1>   //header fields










         <RECORD2> //csv values corresponding header


          <C3>6/10/2019 12:00:00 AM</C3>












      Now requirement is to create 3 rows from above input like one for Aminie ,Carbon and Corrosion


      transformed Output:






















      Can you please assist how we can achieve it.

      Appreciate your earlier reply.


        • 1. Re: Creating multiple rows from one record in xslt
          Martien van den Akker



          Do the records repeat, so that there could also be a RECORD3 and RECORD4, or is there only a RECORD1 and RECORD2? If they repeat, then do a for loop over every //Root-Element/* element. Inside the for loop you could do an if that <xsl:if test="local-name()!='RECORD1'">...</xsl:if> you would call a separate named template for the record, skipping RECORD1. Or you add the test to the for loop condition: //Root-Element/*[local-name!='RECORD1'] .


          Apparently the elements in the RECORD2 correspond to the headers in the first line. So in the named template you can add 3 times the target element for each nutricion/chemical <plant_txns>.

          An example is:

          <xsl:template name="transformPlantRecords">

          <xsl:param name="record">


               <plant_code><xsl:value-of select="$record/C2"/></plant_code>

               <tag><xsl:value-of select="//RECORD1/C4"/></tag>

               <tag_value><xsl:value-of select="$record/C4"/></tag_value>




          Then in the <xsl:for-each select = "//Root-Element/*[local-name!='RECORD1']">, you would have something like:

          <xsl:call-template name="transformPlantRecords">

            <xsl:with-param name="record" select="."/>


          This would need a bit of debugging, since I type this just by heart. But this should help you on track.