xslt 标签取集合第一条数据,对于XSLT中的每个循环,仅通过第一条记录

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:

,

,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值