Trying to convert XML to CSV for the XML Below:
{70BF3A9B-9111-48D8-93B4-C6232E74307F}
http://tempuri.org/example/find
AB01029407
2020-05-07T11:23:08
2
4598
MIXD
MY COMPANY Ltd1
GB 823825133
AB01029407
TRF
SEPA
MY COMPANY Ltd
Address Line 1
Address Line 2
CB
98
ABC123
SLEV
Not-Provided
2198.00
SWIFT01
Creditor Name
tests
Chicago
US
98
1345
Not-Provided
2400.00
SWIFT01
Creditor Name1
tests
Chicago
US
98
123456765
XSLT i have used is :
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://schemas.microsoft.com/dynamics/2011/01/documents/Message"
xmlns:ns2="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">
select="concat($header/ns2:MsgId,',',
$header/ns2:CreDtTm,',',
$header/ns2:NbOfTxs,',',
$header/ns2:CtrlSum,',',
$header/ns2:Grpg,',',
$header/ns2:InitgPty/ns2:Nm,',',
$header/ns2:InitgPty/ns2:Id/ns2:OrgId/ns2:TaxIdNb)"/>
select="concat($pmt/ns2:PmtInfId,',',
$pmt/ns2:PmtMtd,',',
$pmt/ns2:PmtTpInf/ns2:SvcLvl/ns2:Cd,',',
$pmt/ns2:Dbtr/ns2:Nm,',',
$pmt/ns2:Dbtr/ns2:PstlAdr/ns2:AdrLine[1],',',
$pmt/ns2:Dbtr/ns2:PstlAdr/ns2:AdrLine[2],',',
$pmt/ns2:Dbtr/ns2:PstlAdr/ns2:Ctry,',',
$pmt/ns2:DbtrAcct/ns2:Id/ns2:IBAN,',',
$pmt/ns2:DbtrAgt/ns2:FinInstnId/ns2:BIC,',',
$pmt/ns2:ChrgBr)"/>
select="concat($pmt/ns2:CdtTrfTxInf/ns2:PmtId/ns2:EndToEndId,',',
$pmt/ns2:CdtTrfTxInf/ns2:Amt/ns2:InstdAmt,',',
$pmt/ns2:CdtTrfTxInf/ns2:CdtrAgt/ns2:FinInstnId/ns2:BIC,',',
$pmt/ns2:CdtTrfTxInf/ns2:Cdtr/ns2:Nm,',',
$pmt/ns2:CdtTrfTxInf/ns2:Cdtr/ns2:PstlAdr/ns2:AdrLine[1],',',
$pmt/ns2:CdtTrfTxInf/ns2:Cdtr/ns2:PstlAdr/ns2:AdrLine[2],',',
$pmt/ns2:CdtTrfTxInf/ns2:Cdtr/ns2:PstlAdr/ns2:Ctry,',',
$pmt/ns2:CdtTrfTxInf/ns2:CdtrAcct/ns2:Id/ns2:IBAN,',',
$pmt/ns2:CdtTrfTxInf/ns2:RmtInf/ns2:Ustrd)"/>
,
,
I got the output as below:
AB01029407,2020-05-07T11:23:08,2,4598,MIXD,MY COMPANY Ltd1,GB 823825133,AB01029407,TRF,SEPA,MY COMPANY Ltd,Address Line 1,Address Line 2,CB,98,ABC123,SLEV,Not-Provided,2198.00,SWIFT01,Creditor Name,tests,Chicago,US,98,1345
AB01029407,2020-05-07T11:23:08,2,4598,MIXD,MY COMPANY Ltd1,GB 823825133,AB01029407,TRF,SEPA,MY COMPANY Ltd,Address Line 1,Address Line 2,CB,98,ABC123,SLEV,Not-Provided,2198.00,SWIFT01,Creditor Name,tests,Chicago,US,98,1345
Desired output is:
AB01029407,2020-05-07T11:23:08,2,4598,MIXD,MY COMPANY Ltd1,GB 823825133,AB01029407,TRF,SEPA,MY COMPANY Ltd,Address Line 1,Address Line 2,CB,98,ABC123,SLEV,Not-Provided,2198.00,SWIFT01,Creditor Name,tests,Chicago,US,98,1345
AB01029407,2020-05-07T11:23:08,2,4598,MIXD,MY COMPANY Ltd1,GB 823825133,AB01029407,TRF,SEPA,MY COMPANY Ltd,Address Line 1,Address Line 2,CB,98,ABC123,SLEV,Not-Provided,2400.00,SWIFT01,Creditor Name1,tests,Chicago,US,98,123456765
Could you please correct this, unable to understand where i am doing wrong.
Thanks
解决方案
I find these endless concat() statements unreadable. I would suggest you change them to explicit instructions in the form of:
,
Some indentation would also be useful for improving readability.
Anyway, your mistake is defining the $CdtTrfTxInfText variable outside of the xsl:for-each instruction. This populates the variable with values from the first CdtTrfTxInf node - and then you simply repeat these values for each occurrence of CdtTrfTxInf.
Try getting rid of the variable and getting the values directly from the current node within the xsl:for-each instruction:
,
,