0

I have input XML as

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02">
    <BkToCstmrDbtCdtNtfctn>
        <GrpHdr>
            <MsgId>FRDA000003421606</MsgId>
            <AddtlInf>BatchAccounting</AddtlInf>
        </GrpHdr>
        <Ntfctn>
            <Id>AC730486180000000002</Id>
            <ElctrncSeqNb>1234</ElctrncSeqNb>
            <Acct>
                <Svcr>
                    <FinInstnId>
                        <Othr>
                            <Id>40457258</Id>
                        </Othr>
                    </FinInstnId>
                </Svcr>
            </Acct>
            <Ntry>
                <Amt Ccy="EUR">126</Amt>
                <CdtDbtInd>CRDT</CdtDbtInd>
                <Sts>BOOK</Sts>
                <BkTxCd>
                    <Domn>
                        <Cd>PMNT</Cd>
                        <Fmly>
                            <Cd>RDDT</Cd>
                            <SubFmlyCd>ESDD</SubFmlyCd>
                        </Fmly>
                    </Domn>
                    <Prtry>
                        <Issr>SWIFT</Issr>
                    </Prtry>
                </BkTxCd>
                <AmtDtls>
                    <InstdAmt>
                        <Amt Ccy="EUR">126</Amt>
                        <CcyXchg/>
                    </InstdAmt>
                    <TxAmt>
                        <Amt Ccy="EUR">126</Amt>
                        <CcyXchg/>
                    </TxAmt>
                    <CntrValAmt>
                        <Amt Ccy="EUR">126</Amt>
                        <CcyXchg/>
                    </CntrValAmt>
                </AmtDtls>
                <Chrgs>
                    <TtlChrgsAndTaxAmt Ccy="AAA">0</TtlChrgsAndTaxAmt>
                    <Amt Ccy="AAA">0</Amt>
                    <CdtDbtInd>DBIT</CdtDbtInd>
                    <Tp>
                        <Cd>COMM</Cd>
                    </Tp>
                    <Rate>0</Rate>
                    <Br>SLEV</Br>
                    <Pty>
                        <FinInstnId>
                            <BIC>AAAAAA20</BIC>
                            <ClrSysMmbId>
                                <ClrSysId>
                                    <Cd>a</Cd>
                                </ClrSysId>
                                <MmbId>a</MmbId>
                            </ClrSysMmbId>
                            <Nm>a</Nm>
                            <PstlAdr>
                                <AdrTp>MLTO</AdrTp>
                                <Dept>a</Dept>
                                <SubDept>a</SubDept>
                                <StrtNm>a</StrtNm>
                                <BldgNb>a</BldgNb>
                                <PstCd>a</PstCd>
                                <TwnNm>a</TwnNm>
                                <CtrySubDvsn>a</CtrySubDvsn>
                                <Ctry>AA</Ctry>
                                <AdrLine>a</AdrLine>
                            </PstlAdr>
                            <Othr>
                                <Id>a</Id>
                                <SchmeNm>
                                    <Cd>a</Cd>
                                </SchmeNm>
                                <Issr>a</Issr>
                            </Othr>
                        </FinInstnId>
                        <BrnchId>
                            <Id>a</Id>
                            <Nm>a</Nm>
                            <PstlAdr>
                                <AdrTp>ADDR</AdrTp>
                                <Dept>a</Dept>
                                <SubDept>a</SubDept>
                                <StrtNm>a</StrtNm>
                                <BldgNb>a</BldgNb>
                                <PstCd>a</PstCd>
                                <TwnNm>a</TwnNm>
                                <CtrySubDvsn>a</CtrySubDvsn>
                                <Ctry>AA</Ctry>
                                <AdrLine>a</AdrLine>
                            </PstlAdr>
                        </BrnchId>
                    </Pty>
                    <Tax>
                        <Id>a</Id>
                        <Rate>0</Rate>
                        <Amt Ccy="AAA">0</Amt>
                    </Tax>
                </Chrgs>
                <NtryDtls>
                    <Btch>
                        <MsgId>FG00000000000y88sd</MsgId>
                        <NbOfTxs>2</NbOfTxs>
                    </Btch>
                    <TxDtls>
                        <Refs>
                            <AcctSvcrRef>FRDA00000342</AcctSvcrRef>
                            <EndToEndId>E2E220161205123001</EndToEndId>
                            <TxId>FRDA00004341</TxId>
                            <MndtId>MANsecT1COR1201006</MndtId>
                        </Refs>
                        <AmtDtls/>
                        <Chrgs>
                            <TtlChrgsAndTaxAmt Ccy="BBB">0</TtlChrgsAndTaxAmt>
                            <Amt Ccy="BBB">0</Amt>
                            <CdtDbtInd>DBIT</CdtDbtInd>
                            <Tp>
                                <Cd>COMM</Cd>
                            </Tp>
                            <Rate>0</Rate>
                            <Br>SLEV</Br>
                            <Pty>
                                <FinInstnId>
                                    <BIC>BBBBB20</BIC>
                                    <ClrSysMmbId>
                                        <ClrSysId>
                                            <Cd>b</Cd>
                                        </ClrSysId>
                                        <MmbId>b</MmbId>
                                    </ClrSysMmbId>
                                    <Nm>b</Nm>
                                    <PstlAdr>
                                        <AdrTp>MLTO</AdrTp>
                                        <Dept>b</Dept>
                                        <SubDept>b</SubDept>
                                        <StrtNm>b</StrtNm>
                                        <BldgNb>b</BldgNb>
                                        <PstCd>b</PstCd>
                                        <TwnNm>b</TwnNm>
                                        <CtrySubDvsn>b</CtrySubDvsn>
                                        <Ctry>BB</Ctry>
                                        <AdrLine>b</AdrLine>
                                    </PstlAdr>
                                    <Othr>
                                        <Id>b</Id>
                                        <SchmeNm>
                                            <Cd>b</Cd>
                                        </SchmeNm>
                                        <Issr>b</Issr>
                                    </Othr>
                                </FinInstnId>
                                <BrnchId>
                                    <Id>b</Id>
                                    <Nm>b</Nm>
                                    <PstlAdr>
                                        <AdrTp>bDDR</AdrTp>
                                        <Dept>b</Dept>
                                        <SubDept>b</SubDept>
                                        <StrtNm>b</StrtNm>
                                        <BldgNb>b</BldgNb>
                                        <PstCd>b</PstCd>
                                        <TwnNm>b</TwnNm>
                                        <CtrySubDvsn>b</CtrySubDvsn>
                                        <Ctry>BB</Ctry>
                                        <AdrLine>b</AdrLine>
                                    </PstlAdr>
                                </BrnchId>
                            </Pty>
                            <Tax>
                                <Id>b</Id>
                                <Rate>0</Rate>
                                <Amt Ccy="BBB">0</Amt>
                            </Tax>
                        </Chrgs>
                        <RltdPties>
                            <Cdtr>
                                <Nm>Creditor 1</Nm>
                                <PstlAdr>
                                    <Ctry>PT</Ctry>
                                    <AdrLine>TEST TEST</AdrLine>
                                    <AdrLine>TEST TEST</AdrLine>
                                </PstlAdr>
                                <CtryOfRes>PT</CtryOfRes>
                            </Cdtr>
                            <CdtrAcct>
                                <Id>
                                    <IBAN>FR7630588000010050000143176</IBAN>
                                </Id>
                            </CdtrAcct>
                        </RltdPties>
                        <RltdDts>
                            <AccptncDtTm>2016-12-06T04:01:10</AccptncDtTm>
                            <IntrBkSttlmDt>2016-12-07</IntrBkSttlmDt>
                        </RltdDts>
                        <AddtlTxInf/>
                    </TxDtls>
                    <TxDtls>
                        <Refs>
                            <AcctSvcrRef>FRDA00000343</AcctSvcrRef>
                            <EndToEndId>E2E120161205123003</EndToEndId>
                            <TxId>FRDA00003343</TxId>
                            <MndtId>MANFRST1COR1201003</MndtId>
                        </Refs>
                        <AmtDtls/>
                        <RltdPties>
                            <Cdtr>
                                <Nm>Creditor 1</Nm>
                                <PstlAdr>
                                    <Ctry>PT</Ctry>
                                    <AdrLine>TEST TEST</AdrLine>
                                    <AdrLine>TEST TEST</AdrLine>
                                </PstlAdr>
                                <CtryOfRes>PT</CtryOfRes>
                            </Cdtr>
                            <CdtrAcct>
                                <Id>
                                    <IBAN>FR7630588000010050000143176</IBAN>
                                </Id>
                            </CdtrAcct>
                        </RltdPties>
                        <RltdDts>
                            <AccptncDtTm>2016-12-06T04:01:10</AccptncDtTm>
                            <IntrBkSttlmDt>2016-12-07</IntrBkSttlmDt>
                        </RltdDts>
                        <AddtlTxInf/>
                    </TxDtls>
                </NtryDtls>
                <AddtlNtryInf>ENRICHED|TRUE SETT_METHOD|SEPA IAT_IND|FALSE DOMESTIC_IND|FALSE PRIORITY_IND|FALSE</AddtlNtryInf>
            </Ntry>
        </Ntfctn>
    </BkToCstmrDbtCdtNtfctn>
</Document>

I am trying to extract child elements from a parent node TxDtls, where TxDtls can occur 1 or more than one time in the input XML. Below is the XLST I tried to use

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:od="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" exclude-result-prefixes="od">

  <xsl:output method="xml" indent="no" omit-xml-declaration="yes"/>
  <xsl:strip-space elements="od:*"/>

   <xsl:template match="@* | node()" name="TransactionDetails">
       <xsl:apply-templates/>
     </xsl:template>


     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:Refs">
     <xsl:copy-of select="."/>
     <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:AmtDtls">
     <xsl:copy-of select="."/>
     <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:Avlbty">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:BkTxCd">
     <xsl:copy-of select="."/>
     <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:Chrgs">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:Intrst">
     <xsl:copy-of select="."/>
     <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RltdPties">
     <xsl:copy-of select="."/>
     <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RltdAgts">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:Purp">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RltdRmtInf">
     <xsl:copy-of select="."/>
      <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RmtInf">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RltdDts">
     <xsl:copy-of select="."/>
     <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RltdPric">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RltdQties">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:FinInstrmId">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:Tax">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:RtrInf">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:CorpActn">
     <xsl:copy-of select="."/>    
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:SfkpgAcct">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

     <xsl:template match="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/od:AddtlTxInf">
       <xsl:copy-of select="."/>
       <xsl:text>TGST</xsl:text>
   </xsl:template>

</xsl:stylesheet>

Expected output as:

<Refs xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><AcctSvcrRef>FRDA00000342</AcctSvcrRef><EndToEndId>E2E220161205123001</EndToEndId><TxId>FRDA00004341</TxId><MndtId>MANsecT1COR1201006</MndtId></Refs>TGST<AmtDtls xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"/>TGST<Chrgs xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><TtlChrgsAndTaxAmt Ccy="BBB">0</TtlChrgsAndTaxAmt><Amt Ccy="BBB">0</Amt><CdtDbtInd>DBIT</CdtDbtInd><Tp><Cd>COMM</Cd></Tp><Rate>0</Rate><Br>SLEV</Br><Pty><FinInstnId><BIC>BBBBB20</BIC><ClrSysMmbId><ClrSysId><Cd>b</Cd></ClrSysId><MmbId>b</MmbId></ClrSysMmbId><Nm>b</Nm><PstlAdr><AdrTp>MLTO</AdrTp><Dept>b</Dept><SubDept>b</SubDept><StrtNm>b</StrtNm><BldgNb>b</BldgNb><PstCd>b</PstCd><TwnNm>b</TwnNm><CtrySubDvsn>b</CtrySubDvsn><Ctry>BB</Ctry><AdrLine>b</AdrLine></PstlAdr><Othr><Id>b</Id><SchmeNm><Cd>b</Cd></SchmeNm><Issr>b</Issr></Othr></FinInstnId><BrnchId><Id>b</Id><Nm>b</Nm><PstlAdr><AdrTp>bDDR</AdrTp><Dept>b</Dept><SubDept>b</SubDept><StrtNm>b</StrtNm><BldgNb>b</BldgNb><PstCd>b</PstCd><TwnNm>b</TwnNm><CtrySubDvsn>b</CtrySubDvsn><Ctry>BB</Ctry><AdrLine>b</AdrLine></PstlAdr></BrnchId></Pty><Tax><Id>b</Id><Rate>0</Rate><Amt Ccy="BBB">0</Amt></Tax></Chrgs>TGST<RltdPties xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><Cdtr><Nm>Creditor 1</Nm><PstlAdr><Ctry>PT</Ctry><AdrLine>TEST TEST</AdrLine><AdrLine>TEST TEST</AdrLine></PstlAdr><CtryOfRes>PT</CtryOfRes></Cdtr><CdtrAcct><Id><IBAN>FR7630588000010050000143176</IBAN></Id></CdtrAcct></RltdPties>TGST<RltdDts xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><AccptncDtTm>2016-12-06T04:01:10</AccptncDtTm><IntrBkSttlmDt>2016-12-07</IntrBkSttlmDt></RltdDts>TGST<AddtlTxInf xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"/>TGST<Refs xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><AcctSvcrRef>FRDA00000343</AcctSvcrRef><EndToEndId>E2E120161205123003</EndToEndId><TxId>FRDA00003343</TxId><MndtId>MANFRST1COR1201003</MndtId></Refs>TGST<AmtDtls xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"/>TGST<RltdPties xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><Cdtr><Nm>Creditor 1</Nm><PstlAdr><Ctry>PT</Ctry><AdrLine>TEST TEST</AdrLine><AdrLine>TEST TEST</AdrLine></PstlAdr><CtryOfRes>PT</CtryOfRes></Cdtr><CdtrAcct><Id><IBAN>FR7630588000010050000143176</IBAN></Id></CdtrAcct></RltdPties>TGST<RltdDts xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"><AccptncDtTm>2016-12-06T04:01:10</AccptncDtTm><IntrBkSttlmDt>2016-12-07</IntrBkSttlmDt></RltdDts>TGST<AddtlTxInf xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"/>TGST

I am getting the expected output but with namespaces. I want to remove the namespaces.

Need input in building the XSLT to get the desired out.

Thanking in advance

Updated XLST

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:od="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" exclude-result-prefixes="od">

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
  <xsl:strip-space elements="od:*"/>

    <xsl:template match="*" priority="2">
    <xsl:element name="{local-name()}">        
        <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
    </xsl:teqmplate>

    <xsl:template match="@*|node()">
      <xsl:copy-of select="."/>
      <xsl:text>TGST</xsl:text>
    </xsl:template>

    <xsl:template match="/">
        <xsl:apply-templates select="od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls/*" />
    </xsl:template>

</xsl:stylesheet>
  • Nikhil, please present a minimal example like `firstsecond` and the minimal XSLT. This will be much easier for us (me) to help. – Stefan Dec 29 '16 at 00:15
  • It is unclear which elements you are trying to extract, and your expected output is not XML. – Michael Vehrs Dec 29 '16 at 08:23
  • @Stefan, @MichaelVehrs: Sorry for the minimal information on output. I have modified the question and removed XML from expected output. Also the elements I want to extract are under parent element `od:Document/od:BkToCstmrDbtCdtNtfctn/od:Ntfctn/od:Ntry/od:NtryDtls/od:TxDtls` – Nikhil Pradhan Dec 29 '16 at 09:00
  • @Stefan : My requirement is to create a buffer(as shown in output). This buffer would then be passed onto another system which will in turn generate the final output xml. – Nikhil Pradhan Dec 29 '16 at 09:04
  • @MichaelVehrs: My requirement is to create a buffer(as shown in output). This buffer would then be passed onto another system which will in turn generate the final output xml. – Nikhil Pradhan Dec 29 '16 at 09:04
  • @NikhilPradhan Your output does not look as if you were extracting all children of TxDtls, only some. – Michael Vehrs Dec 29 '16 at 09:21
  • @MichaelVehrs: Thanks for the reply. Actually the list of child elements in TxDtls about 20 but each individual child element further has numerous child elements in them (i think more than 200) and so I did not show all the tags in the output. But in the actual output I want to extract all the child elements of TxDtls – Nikhil Pradhan Dec 29 '16 at 11:24
  • @MichaelVehrs I have come up with a XSLT to get the desired output but there are namespaces in the output. I need help in removing those. Could you please provide help in regarding this. Thanks in advance – Nikhil Pradhan Dec 30 '16 at 13:10
  • Look here: http://stackoverflow.com/questions/5268182/how-to-remove-namespaces-from-xml-using-xslt – Michael Vehrs Dec 30 '16 at 13:27
  • @MichaelVehrs I have come up with a new XSLT based on your suggested link but now I am unable to get the text TGST before every tag. The new XSLT is in the question. Could you please help on this. Thanks in advance – Nikhil Pradhan Jan 04 '17 at 10:25

1 Answers1

0

You need to put the text element somewhere else:

<xsl:template match="*" priority="2">
  <xsl:text>TGST</xsl:text>
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>
Michael Vehrs
  • 3,293
  • 11
  • 10