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

    Creating multiple rows from one record in xslt

    3426083

      Dear All,

       

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

       

      <Receive1_Read_InputVariable>

      <part  name="body">

        <Root-Element>

         <RECORD1>   //header fields

          <C2>Plant</C2>

          <C3>TimeStamp</C3>

          <C4>Amine</C4>

          <C5>Amine_UOM</C5>

          <C6>Carbon</C6>

          <C7>Carbon_UOM</C7>

          <C8>Corrosion</C8>

          <C9>Corrosion_UOM</C9>

         </RECORD1>

         <RECORD2> //csv values corresponding header

          <C2>SAW</C2>

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

          <C4>36693.6087285655</C4>

          <C5/>

          <C6>1861.09620848459</C6>

          <C7/>

          <C8>105039.572083346</C8>

          <C9/>

         </RECORD2>

        </Root-Element>

      </part>

      </Receive1_Read_InputVariable>

       

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

       

      transformed Output:

      <SAW_RAW>

      <plant_txns>

           <plant_code>SAW</plant_code>

           <tag>Aminie</tag>

           <tag_value>36693.6087285655</tag_value>

           <tag_date>06/10/2019</tag_date>

        </plant_txns>

      <plant_txns>

             <plant_code>SAW</plant_code>

             <tag>Carbon</tag>

             <tag_value>1861.09620848459</tag_value>

             <tag_date>06/10/2019</tag_date>

      </plant_txns>

      <plant_txns>

             <plant_code>SAW</plant_code>

             <tag>Corrosion</tag>

             <tag_value>105039.572083346</tag_value>

             <tag_date>06/10/2019</tag_date>

        </plant_txns>

      </SAW_RAW>

       

      Can you please assist how we can achieve it.

      Appreciate your earlier reply.

      Thanks

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

          Hi,

           

          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_txns>

               <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>

               <tag_date>$record/C3</tag_date>

            </plant_txns>

          </xsl:template>

          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="."/>

          </xsl:call-template>

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


          Regards,
          Martien