Covert xml to csv using xsltproc in shell script

Hi,

I am not familiar with shell scripting. Please help to convert xml files to csv files using xsltproc command in bash script. Find the xml sample

<?xml version="1.0"?>

-<Source xmlns="link">

<CompanyCd>DSP</CompanyCd>

<SrcSysCd>DSPS</SrcSysCd>

<CountryCd>45</CountryCd>


-<Product>

<Id>582444f3</Id>

<TypeCd>Account A</TypeCd>

<StartDt>2018-02-05T00:00:00+01:00</StartDt>

<StatusCd>SUBMITTED</StatusCd>

<SrcAlignmentNm>SM13_V17_1001</SrcAlignmentNm>


-<Customer>

<CustomerId>5aa56664</CustomerId>

<CustomerTypeCd>HCP</CustomerTypeCd>

<CustomerAltId1>DEBU05110673</CustomerAltId1>

</Customer>


-<Detail>

<DetailId>582444f3</DetailId>

<GroupSrcId>a003E0000</GroupSrcId>

<GroupSrcNm>KENPUL</GroupSrcNm>

<DetailSeq>1</DetailSeq>

</Detail>

</Product>

</Source>

Thanks

You need to attempt to write your own script first. We are here to help you, not do your work for you.

Hi ,

Please find the below code which i have tried, able to get the output, but i need the output in a seperate csv file. how to perform it

xsltproc x.xslt test.xml 

x.xslt code is as below

<xsl:stylesheet version="1.0" >
<xsl:output method="text"/>

<xsl:template match ="/">
         <xsl:for-each select="Source/Product">

   <xsl:value-of select="Id" />
         <xsl:text>;</xsl:text>
   <xsl:value-of select="TypeCd"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="StartDt"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="StatusCd"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/CustomerId"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/CustomerTypeCd"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/CustomerAltId1"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/Detail/DetailId"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/Detail/GroupSrcId"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/Detail/GroupSrcNm"/>
         <xsl:text>;</xsl:text>
   <xsl:value-of select="Customer/Detail/DetailSeq"/>
                       <xsl:text>
</xsl:text>
                </xsl:for-each>
       </xsl:template>
</xsl:stylesheet>

--- Post updated at 09:30 PM ---

Hi

I got it in seperate csv file using the command

xsltproc x.xslt test.xml > output.csv