Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

XSLT XML to ABAP with list

hi experts

I am in a rut trying to transform XML to ABAP internal tables and everything is working well except this piece.  I am looking for assistance as everything I am trying is not working.

Here the is XML returned.  Again, I am fine with everything but in the <sources> element.  I have added the things I have tried at the bottom of this thread.  I really appreciate any help on this.

Thanks,

Chris

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<company>

    <companyId>

        111

    </companyId>

    <websites>

        <website>http://www.test.com</website>

    </websites>

    <sources>

        <source>netprospex</source>

        <source>jigsaw</source>

        <source>cortera</source>

        <source>insidetest</source>

        <source>userAddedData</source>

        <source>capitaliq</source>

        <source>crowdflower</source>

    </sources>

    <city>test</city>

    <companyStatus>Operating</companyStatus>

    <companyType>Private</companyType>

    <country>United States</country>

    <employees>3000</employees>

    <fax>111-111-1111</fax>

    <financialYearEnd>0</financialYearEnd>

    <industry>Computer Software</industry>

    <naics>000000</naics>

    <naicsDescription>test</naicsDescription>

    <name>test</name>

    <phone>+1 111 111 1111</phone>

    <revenue>0</revenue>

    <sic>0000</sic>

    <sicDescription>Services-Prepackaged Software</sicDescription>

    <state>NA</state>

    <street>test</street>

    <subIndustry>test</subIndustry>

    <subsidiary>false</subsidiary>

    <zip>00000</zip>

</company>

My XSLT is again working fine but the <sources> list items are not filling properly.  They way it is now, I get the first item 7 times in the nested internal table.

<xsl:template match="/">
     <ZRESULTS>
       <COMPANYDETAILS>
         <xsl:for-each select="company">
           <ZICOMPANY_DETAILS>
             <COMPANY_ID>
               <xsl:value-of select="companyId"/>
             </COMPANY_ID>
             <NAME>
               <xsl:value-of select="name"/>
             </NAME>
             <COMPANY_TYPE>
               <xsl:value-of select="companyType"/>
             </COMPANY_TYPE>
             <COMPANY_STATUS>
               <xsl:value-of select="companyStatus"/>
             </COMPANY_STATUS>
             <INDUSTRY>
               <xsl:value-of select="industry"/>
             </INDUSTRY>
             <SUB_INDUSTRY>
               <xsl:value-of select="subIndustry"/>
             </SUB_INDUSTRY>
             <STREET>
               <xsl:value-of select="street"/>
             </STREET>
             <CITY>
               <xsl:value-of select="city"/>
             </CITY>
             <STATE>
               <xsl:value-of select="state"/>
             </STATE>
             <ZIP>
               <xsl:value-of select="zip"/>
             </ZIP>
             <COUNTRY>
               <xsl:value-of select="country"/>
             </COUNTRY>
             <PHONE>
               <xsl:value-of select="phone"/>
             </PHONE>
             <FAX>
               <xsl:value-of select="fax"/>
             </FAX>
             <REVENUE>
               <xsl:value-of select="revenue"/>
             </REVENUE>
             <EMPLOYEES>
               <xsl:value-of select="employees"/>
             </EMPLOYEES>
             <SUBSIDIARY>
               <xsl:value-of select="subsidiary"/>
             </SUBSIDIARY>
             <SIC>
               <xsl:value-of select="sic"/>
             </SIC>
             <SIC_DESCRIPTION>
               <xsl:value-of select="sicDescription"/>
             </SIC_DESCRIPTION>
             <NAICS>
               <xsl:value-of select="naics"/>
             </NAICS>
             <NAICS_DESCRIPTION>
               <xsl:value-of select="naicsDescription"/>
             </NAICS_DESCRIPTION>
             <FINANCIAL_YEAR_END>
               <xsl:value-of select="financialYearEnd"/>
             </FINANCIAL_YEAR_END>
             <EQUIFAX_ID>
               <xsl:value-of select="equifaxId"/>
             </EQUIFAX_ID>
             <FORTUNE_RANKING>
               <xsl:value-of select="fortuneRanking"/>
             </FORTUNE_RANKING>
             <COMPANY_DESCRIPTION>
               <xsl:value-of select="description"/>
             </COMPANY_DESCRIPTION>

             <SOURCESLIST>
               <xsl:for-each select="company/sources/source">
                 <ZSOURCES>
                   <SOURCE>
                     <xsl:value-of select="source"/>
                   </SOURCE>
                 </ZSOURCES>
               </xsl:for-each>
             </SOURCESLIST>

             <TICKERS>
               <xsl:for-each select="//company/tickers">
                 <ZTICKER>
                   <EXCHANGE_SYMBOL>
                     <xsl:value-of select="exchange"/>
                   </EXCHANGE_SYMBOL>
                   <TICKER_NAME>
                     <xsl:value-of select="tickerName"/>
                   </TICKER_NAME>
                 </ZTICKER>
               </xsl:for-each>
             </TICKERS>

           </ZCOMPANY_DETAILS>
         </xsl:for-each>
       </COMPANYDETAILS>
     </ZRESULTS>
   </xsl:template>

</xsl:transform>


when I went to XSLT Tryit Editor v1.0&lt;/title&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/tryit.css&… and tried it there, it didnt work as well.  I tried making  <xsl:for-each select="company/sources/source"<xsl:for-each select="company/sources"> and all I get is the first item in the list. 

Tags:
replied

All,I figured it out.

This is how the sources piece needs to look in order to work.

<SOURCESLIST>
               <xsl:for-each select="sources/source">
                 <ZSOURCES>
                   <SOURCE>
                     <xsl:value-of select="."/>
                   </SOURCE>
                 </ZSOURCES>
               </xsl:for-each>
             </SOURCESLIST>


Pretty simple once I figured it out but dont we all say that.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question