0

For unknow reason SEPA payment file cannot converted to linear xml.

I tried xml file and stylesheet below using http://http://www.utilities-online.info/xsltransformation

result xml ei empty. Selector

<xsl:template match="TxAmt/*">

must find mach in file so it should return one record. Namespaces are defined in XSL file.

How to fix ?

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <BkToCstmrDbtCdtNtfctn>
    <GrpHdr>
      <MsgId>8FE0A83C6506239E141E7CD197C0E588</MsgId>
      <CreDtTm>2017-01-10T16:42:05.399+02:00</CreDtTm>
    </GrpHdr>
    <Ntfctn>
      <Id>8FE0A83C6506239E141E7CD197C0E588</Id>
      <CreDtTm>2017-01-10T16:42:05.399+02:00</CreDtTm>
      <Acct>
        <Id>
          <IBAN>XX891010000007099224</IBAN>
        </Id>
        <Ccy>EUR</Ccy>
        <Ownr>
          <Nm>Test Ltd</Nm>
          <PstlAdr>
            <AdrLine>test</AdrLine>
          </PstlAdr>
          <Id>
            <OrgId>
              <Othr>
                <Id>102167</Id>
                <SchmeNm>
                  <Cd>COID</Cd>
                </SchmeNm>
              </Othr>
            </OrgId>
          </Id>
        </Ownr>
        <Svcr>
          <FinInstnId>
            <BIC>EEUHEE2X</BIC>
            <Nm>Bank</Nm>
            <PstlAdr>
              <AdrLine>Test</AdrLine>
            </PstlAdr>
          </FinInstnId>
        </Svcr>
      </Acct>
      <Ntry>
        <Amt Ccy="EUR">2.50</Amt>
        <CdtDbtInd>CRDT</CdtDbtInd>
        <Sts>BOOK</Sts>
        <BookgDt>
          <Dt>2017-01-10</Dt>
        </BookgDt>
        <ValDt>
          <Dt>2017-01-10</Dt>
        </ValDt>
        <AcctSvcrRef>RO1433781673L02</AcctSvcrRef>
        <BkTxCd>
          <Domn>
            <Cd>PMNT</Cd>
            <Fmly>
              <Cd>RCDT</Cd>
              <SubFmlyCd>BOOK</SubFmlyCd>
            </Fmly>
          </Domn>
        </BkTxCd>
        <NtryDtls>
          <TxDtls>
            <Refs>
              <AcctSvcrRef>RO1433781673L02</AcctSvcrRef>
            </Refs>
            <AmtDtls>
              <TxAmt>
                <Amt Ccy="EUR">2.50</Amt>
              </TxAmt>
            </AmtDtls>
            <RltdPties>
              <Dbtr>
                <Nm>EXPRESSLIIN</Nm>
                <Id>
                  <OrgId>
                    <Othr>
                      <Id>6310130</Id>
                      <SchmeNm>
                        <Cd>COID</Cd>
                      </SchmeNm>
                    </Othr>
                  </OrgId>
                </Id>
              </Dbtr>
              <DbtrAcct>
                <Id>
                  <IBAN>XX021010220208830224</IBAN>
                </Id>
              </DbtrAcct>
            </RltdPties>
            <RltdAgts>
              <DbtrAgt>
                <FinInstnId>
                  <BIC>DEUHEE2X</BIC>
                  <Nm>DEAS</Nm>
                </FinInstnId>
              </DbtrAgt>
            </RltdAgts>
            <RmtInf>
              <Ustrd>Test3</Ustrd>
            </RmtInf>
          </TxDtls>
        </NtryDtls>
      </Ntry>
    </Ntfctn>
  </BkToCstmrDbtCdtNtfctn>
</Document>

XSLT:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
  <xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes"/>

  <xsl:template match="/">
    <xsl:element name="VFPData">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="TxAmt/*">

    <xsl:element name="Document-BankCD">
      <xsl:element name="SubFmlyCd">
        <xsl:value-of select="../../../../../BkTxCd/Domn/Fmly/SubFmlyCd"/>
      </xsl:element>


      <xsl:element name="tasusumma">
        <xsl:value-of select="../Amt"/>
      </xsl:element>

      <xsl:element name="raha">
        <xsl:value-of select="../Amt/@Ccy"/>
      </xsl:element>

    </xsl:element>
  </xsl:template>

  <xsl:template match="text()">
  </xsl:template>

  <xsl:template match="*">
    <xsl:apply-templates/>
  </xsl:template>
</xsl:stylesheet>
Andrus
  • 26,339
  • 60
  • 204
  • 378
  • 1
    See: http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k Jan 15 '17 at 17:54
  • xsl defines default namespace as `xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" `. This namespace should resolved without prefix. Should namespace prefix added to every element used in xpath expressions ? – Andrus Jan 15 '17 at 17:59
  • 1
    The declaration of a default namespace in your stylesheet affects only the output, by placing literal result elements in that namespace (which you probably don't want). It plays no role in selecting the nodes in the input. You're probably thinking of `xpath-default-namespace`, which exists in XSLT 2.0. -- "*Should namespace prefix added to every element used in xpath expressions ?*" Only those that are in a namespace - which in your case means all of them. – michael.hor257k Jan 15 '17 at 18:27
  • There are lot of such elements and adding namespace prefix to all of them makes stylesheet difficult to read. – Andrus Jan 15 '17 at 19:15
  • Choose a short prefix, if that's your concern. In any case, if the element is in a namespace, than an expression using only its local name will not select/match it. – michael.hor257k Jan 15 '17 at 19:35
  • Thank you, I got it. You can wrote answer or should I delete question since it is duplicate? – Andrus Jan 15 '17 at 19:43
  • I suggest you delete it. – michael.hor257k Jan 15 '17 at 21:16

1 Answers1

1

Make the following corrections:

  1. Add xmlns:my="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" to stylesheet tag.

  2. Prepend my: to TxAmt/*. From this point the output will include at least empty tags.

  3. Prepend my: to every other tag name in XPaths. Then you will see the values.

For readability reason I added also indent="yes" to output tag. Remove it in the final version.

Below you have corrected XSLT. Note minor simplification of template matching text() nodes.

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:my="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"
>
  <xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8" standalone="yes"/>

  <xsl:template match="/">
    <xsl:element name="VFPData">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="my:TxAmt/*">

    <xsl:element name="Document-BankCD">
      <xsl:element name="SubFmlyCd">
        <xsl:value-of select="../../../../../my:BkTxCd/my:Domn/my:Fmly/my:SubFmlyCd"/>
      </xsl:element>

      <xsl:element name="tasusumma">
        <xsl:value-of select="../my:Amt"/>
      </xsl:element>

      <xsl:element name="raha">
        <xsl:value-of select="../my:Amt/@Ccy"/>
      </xsl:element>

    </xsl:element>
  </xsl:template>

  <xsl:template match="text()"/>

  <xsl:template match="*">
    <xsl:apply-templates/>
  </xsl:template>
</xsl:stylesheet>

Using http://xsltransform.net with your XML I got the following result:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VFPData xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02">
   <Document-BankCD>
      <SubFmlyCd>BOOK</SubFmlyCd>
      <tasusumma>2.50</tasusumma>
      <raha>EUR</raha>
   </Document-BankCD>
</VFPData>
Valdi_Bo
  • 30,023
  • 4
  • 23
  • 41