-1

Convert XML(with document header) to CSV - If I remove the document header in XML file am able to get the expected csv output but if I don't remove the document header in XML file am not getting the expected csv output. Here is my XML

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:secl.010.001.03">
  <SttlmOblgtnRpt>
    <RptParams>
      <RptId>021/ACSET/00210002/20170628/000002</RptId>
      <RptDtAndTm>
        <DtTm>2017-06-28T00:00:00</DtTm>
      </RptDtAndTm>
    </RptParams>
    <Pgntn>
      <PgNb>1</PgNb>
      <LastPgInd>true</LastPgInd>
    </Pgntn>
    <ClrMmb>
      <PrtryId>
        <Id>00210002</Id>
        <Issr>SETTLING MEMBER</Issr>
      </PrtryId>
    </ClrMmb>
    <RptDtls>
    </RptDtls>
  </SttlmOblgtnRpt>
</Document>

Expected O/P:

RptId,DtTm,PgNb,LastPgInd,Id,Issr 021/ACSET/00210002/20170628/000002,2017-06-28T00:00:00,1,true,00210002,SETTLING MEMBER

Here If I remove the document header in the XML file am getting correct o/p but as per my requirement document header should be there I can't remove it. Please help me .... Thanks.

Mahesh
  • 3
  • 3

1 Answers1

1

Try it this way:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:iso="urn:iso:std:iso:20022:tech:xsd:secl.010.001.03"
exclude-result-prefixes="iso">
<xsl:output method="text" encoding="UTF-8" />

<xsl:template match="/iso:Document">
    <!-- header -->
    <xsl:text>RptId,DtTm,PgNb,LastPgInd,Id,Issr&#10;</xsl:text> 
    <xsl:for-each select="iso:SttlmOblgtnRpt">
        <xsl:value-of select="iso:RptParams/iso:RptId" />
        <xsl:text>,</xsl:text>
        <xsl:value-of select="iso:RptParams/iso:RptDtAndTm/iso:DtTm" />
        <xsl:text>,</xsl:text>
        <xsl:value-of select="iso:Pgntn/iso:PgNb" />
        <xsl:text>,</xsl:text>
        <xsl:value-of select="iso:Pgntn/iso:LastPgInd" />
        <xsl:text>,</xsl:text>
        <xsl:value-of select="iso:ClrMmb/iso:PrtryId/iso:Id" />
        <xsl:text>,</xsl:text>
        <xsl:value-of select="iso:ClrMmb/iso:PrtryId/iso:Issr" />
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51