0

I am trying to create an XPath with v1.0 that returns a list of all amount elements Amt[@Ccy="EUR"]. However, it should be noted that if the sibling element of this element CdtDbtInd has the value DBIT, a - should be appended to the beginning of the string. If this is not the case, the string should not be manipulated.

I already managed to append a char at the beginning of the string like so:

//BkToCstmrStmt/Stmt/Ntry[Amt[@Ccy="EUR"]/../CdtDbtInd='DBIT']/concat("-", Amt[@Ccy="EUR"]/text())

This transforms my value like this:

// from
1.00

// to 
-1.00

But this only returns me the values where this is the case ...

Now I somehow need a way that allows me to build this into an if then else condition so i can get the values of every //BkToCstmrStmt/Stmt/Ntry/Amt[@Ccy='EUR'] tag.

for example:

IF "//BkToCstmrStmt/Stmt/Ntry[Amt[@Ccy="EUR"]/../CdtDbtInd='DBIT']" THEN
    concat("-", Amt[@Ccy="EUR"]/text()
ELSE
    Amt[@Ccy="EUR"]/text()

According to this post i tried it with the Becker's Method:

concat(
    substring(
        concat("-", //BkToCstmrStmt/Stmt/Ntry[Amt[@Ccy="EUR"]/../CdtDbtInd='DBIT']/Amt),
        1,
        number(
            //BkToCstmrStmt/Stmt/Ntry[Amt[@Ccy="EUR"]/../CdtDbtInd='DBIT']
        )
        * string-length(concat("-", //BkToCstmrStmt/Stmt/Ntry[Amt[@Ccy="EUR"]/../CdtDbtInd='DBIT']/Amt))
    ),
    substring(
        //BkToCstmrStmt/Stmt/Ntry/Amt[@Ccy="EUR"]/text()
        1,
        number(not(
            //BkToCstmrStmt/Stmt/Ntry[Amt[@Ccy="EUR"]/../CdtDbtInd='DBIT']
        ))
        * string-length(//BkToCstmrStmt/Stmt/Ntry/Amt[@Ccy="EUR"]/text())
    )
)

But this throws the error: Error: Required cardinality of first argument of string-length() is one or zero

Heres my XML File:

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02 camt.053.001.02.xsd">

<BkToCstmrStmt>
  <GrpHdr>
    <MsgId>053D2013-12-27T22:05:03.0N130000005</MsgId>
    <CreDtTm>2013-12-27T22:04:52.0+01:00</CreDtTm>
    <MsgPgntn>
      <PgNb>1</PgNb>
      <LastPgInd>true</LastPgInd>
    </MsgPgntn>
  </GrpHdr>
  <Stmt>
    <Id>0352C5320131227220503</Id>
    <ElctrncSeqNb>130000005</ElctrncSeqNb>
    <CreDtTm>2013-12-27T22:04:52.0+01:00</CreDtTm>
    <Acct>
      <Id>
        <IBAN>DE58740618130100033626</IBAN>
      </Id>
      <Ccy>EUR</Ccy>
      <Ownr>
        <Nm>Testkonto Nummer 2</Nm>
      </Ownr>
      <Svcr>
        <FinInstnId>
          <BIC>GENODEF1PFK</BIC>
          <Nm>VR-Bank Rottal-Inn eG</Nm>
          <Othr>
            <Id>DE 129267947</Id>
            <Issr>UmsStId</Issr>
          </Othr>
        </FinInstnId>
      </Svcr>
    </Acct>
    <Bal>
      <Tp>
        <CdOrPrtry>
          <Cd>PRCD</Cd>
        </CdOrPrtry>
      </Tp>
      <Amt Ccy="EUR">8.50</Amt>
      <CdtDbtInd>CRDT</CdtDbtInd>
      <Dt>
        <Dt>2013-12-27</Dt>
      </Dt>
    </Bal>
    <Bal>
      <Tp>
        <CdOrPrtry>
          <Cd>CLBD</Cd>
        </CdOrPrtry>
      </Tp>
      <Amt Ccy="EUR">18.50</Amt>
      <CdtDbtInd>CRDT</CdtDbtInd>
      <Dt>
        <Dt>2013-12-27</Dt>
      </Dt>
    </Bal>
    <Ntry>
      <Amt Ccy="EUR">2.00</Amt>
      <CdtDbtInd>CRDT</CdtDbtInd>
      <Sts>BOOK</Sts>
      <BookgDt>
        <Dt>2013-12-27</Dt>
      </BookgDt>
      <ValDt>
        <Dt>2013-12-27</Dt>
      </ValDt>
      <AcctSvcrRef>2013122710583450000</AcctSvcrRef>
      <BkTxCd/>
      <NtryDtls>
        <TxDtls>
          <BkTxCd>
            <Prtry>
              <Cd>NMSC+051</Cd>
              <Issr>ZKA</Issr>
            </Prtry>
          </BkTxCd>
          <RltdPties>
            <Dbtr>
              <Nm>Testkonto Nummer 1</Nm>
            </Dbtr>
            <DbtrAcct>
              <Id>
                <Othr>
                  <Id>  740618130000033626</Id>
                  <SchmeNm>
                    <Cd>BBAN</Cd>
                  </SchmeNm>
                </Othr>
              </Id>
            </DbtrAcct>
          </RltdPties>
          <RmtInf>
            <Ustrd>TEST BERWEISUNG MITTELS BLZUND KONTONUMMER - DTA</Ustrd>
          </RmtInf>
        </TxDtls>
      </NtryDtls>
    </Ntry>
    <Ntry>
      <Amt Ccy="EUR">3.00</Amt>
      <CdtDbtInd>CRDT</CdtDbtInd>
      <Sts>BOOK</Sts>
      <BookgDt>
        <Dt>2013-12-27</Dt>
      </BookgDt>
      <ValDt>
        <Dt>2013-12-27</Dt>
      </ValDt>
      <AcctSvcrRef>2013122710583670000</AcctSvcrRef>
      <BkTxCd/>
      <NtryDtls>
        <TxDtls>
          <Refs>
            <EndToEndId>NOTPROVIDED</EndToEndId>
          </Refs>
          <BkTxCd>
            <Prtry>
              <Cd>NMSC+051</Cd>
              <Issr>ZKA</Issr>
            </Prtry>
          </BkTxCd>
          <RltdPties>
            <Dbtr>
              <Nm>Testkonto Nummer 1</Nm>
            </Dbtr>
            <DbtrAcct>
              <Id>
                <IBAN>DE14740618130000033626</IBAN>
              </Id>
            </DbtrAcct>
            <UltmtDbtr>
              <Nm>keine Information vorhanden</Nm>
            </UltmtDbtr>
            <Cdtr>
              <Nm>Josef Schliffenbacher</Nm>
            </Cdtr>
            <CdtrAcct>
              <Id>
                <IBAN>DE58740618130100033626</IBAN>
              </Id>
            </CdtrAcct>
            <UltmtCdtr>
              <Nm>keine Information vorhanden</Nm>
            </UltmtCdtr>
          </RltdPties>
          <RltdAgts>
            <DbtrAgt>
              <FinInstnId>
                <BIC>GENODEF1PFK</BIC>
              </FinInstnId>
            </DbtrAgt>
          </RltdAgts>
          <RmtInf>
            <Ustrd>Test+berweisung mit BIC und IBAN SEPA IBAN: DE14740618130000033626 BIC: GENODEF1PFK</Ustrd>
          </RmtInf>
        </TxDtls>
      </NtryDtls>
    </Ntry>
    <Ntry>
      <Amt Ccy="EUR">1.00</Amt>
      <CdtDbtInd>DBIT</CdtDbtInd>
      <Sts>BOOK</Sts>
      <BookgDt>
        <Dt>2013-12-27</Dt>
      </BookgDt>
      <ValDt>
        <Dt>2013-12-27</Dt>
      </ValDt>
      <AcctSvcrRef>2013122711085260000</AcctSvcrRef>
      <BkTxCd/>
      <NtryDtls>
        <TxDtls>
          <BkTxCd>
            <Prtry>
              <Cd>NTRF+020</Cd>
              <Issr>ZKA</Issr>
            </Prtry>
          </BkTxCd>
          <RltdPties>
            <Cdtr>
              <Nm>Testkonto Nummer 1</Nm>
            </Cdtr>
            <CdtrAcct>
              <Id>
                <Othr>
                  <Id>  740618130000033626</Id>
                  <SchmeNm>
                    <Cd>BBAN</Cd>
                  </SchmeNm>
                </Othr>
              </Id>
            </CdtrAcct>
          </RltdPties>
          <RmtInf>
            <Ustrd>RÜCKBUCHUNG</Ustrd>
          </RmtInf>
        </TxDtls>
      </NtryDtls>
    </Ntry>
    <Ntry>
      <Amt Ccy="EUR">2.50</Amt>
      <CdtDbtInd>CRDT</CdtDbtInd>
      <Sts>BOOK</Sts>
      <BookgDt>
        <Dt>2013-12-27</Dt>
      </BookgDt>
      <ValDt>
        <Dt>2013-12-27</Dt>
      </ValDt>
      <AcctSvcrRef>2013122712332300000</AcctSvcrRef>
      <BkTxCd/>
      <NtryDtls>
        <TxDtls>
          <Refs>
            <EndToEndId>STZV-EtE27122013-11:02-2</EndToEndId>
          </Refs>
          <BkTxCd>
            <Prtry>
              <Cd>NMSC+051</Cd>
              <Issr>ZKA</Issr>
            </Prtry>
          </BkTxCd>
          <RltdPties>
            <Dbtr>
              <Nm>Testkonto Nummer 1</Nm>
            </Dbtr>
            <DbtrAcct>
              <Id>
                <IBAN>DE14740618130000033626</IBAN>
              </Id>
            </DbtrAcct>
            <UltmtDbtr>
              <Nm>keine Information vorhanden</Nm>
            </UltmtDbtr>
            <Cdtr>
              <Nm>Testkonto Nummer 2</Nm>
            </Cdtr>
            <CdtrAcct>
              <Id>
                <IBAN>DE58740618130100033626</IBAN>
              </Id>
            </CdtrAcct>
            <UltmtCdtr>
              <Nm>Testkonto</Nm>
            </UltmtCdtr>
          </RltdPties>
          <RltdAgts>
            <DbtrAgt>
              <FinInstnId>
                <BIC>GENODEF1PFK</BIC>
              </FinInstnId>
            </DbtrAgt>
          </RltdAgts>
          <RmtInf>
            <Ustrd>Sammelueberweisung 1. Zahlung EREF: STZV-EtE27122013-11:02-2 IBAN: DE14740618130000033626 BIC: GENODEF1PFK ABWE: Testkonto</Ustrd>
          </RmtInf>
        </TxDtls>
      </NtryDtls>
    </Ntry>
    <Ntry>
      <Amt Ccy="EUR">3.50</Amt>
      <CdtDbtInd>CRDT</CdtDbtInd>
      <Sts>BOOK</Sts>
      <BookgDt>
        <Dt>2013-12-27</Dt>
      </BookgDt>
      <ValDt>
        <Dt>2013-12-27</Dt>
      </ValDt>
      <AcctSvcrRef>2013122712332300001</AcctSvcrRef>
      <BkTxCd/>
      <NtryDtls>
        <TxDtls>
          <Refs>
            <EndToEndId>STZV-EtE27122013-11:02-1</EndToEndId>
          </Refs>
          <BkTxCd>
            <Prtry>
              <Cd>NMSC+051</Cd>
              <Issr>ZKA</Issr>
            </Prtry>
          </BkTxCd>
          <RltdPties>
            <Dbtr>
              <Nm>Testkonto Nummer 1</Nm>
            </Dbtr>
            <DbtrAcct>
              <Id>
                <IBAN>DE14740618130000033626</IBAN>
              </Id>
            </DbtrAcct>
            <UltmtDbtr>
              <Nm>keine Information vorhanden</Nm>
            </UltmtDbtr>
            <Cdtr>
              <Nm>Testkonto Nummer 2</Nm>
            </Cdtr>
            <CdtrAcct>
              <Id>
                <IBAN>DE58740618130100033626</IBAN>
              </Id>
            </CdtrAcct>
            <UltmtCdtr>
              <Nm>Testkonto</Nm>
            </UltmtCdtr>
          </RltdPties>
          <RltdAgts>
            <DbtrAgt>
              <FinInstnId>
                <BIC>GENODEF1PFK</BIC>
              </FinInstnId>
            </DbtrAgt>
          </RltdAgts>
          <RmtInf>
            <Ustrd>Sammelueberwseisung 2. Zahlung EREF: STZV-EtE27122013-11:02-1 IBAN: DE14740618130000033626 BIC: GENODEF1PFK ABWE: Testkonto</Ustrd>
          </RmtInf>
        </TxDtls>
      </NtryDtls>
    </Ntry>
  </Stmt>
</BkToCstmrStmt>
</Document>

Thanks for any help with this!

5
  • stackoverflow.com/questions/971067/… Commented Dec 4, 2023 at 14:18
  • I've already seen this post, but couldn't get the hang of it in this case ... Commented Dec 4, 2023 at 14:21
  • You've tagged it XPath 1.0, and you're avoiding use of XPath 2.0 if-then-else, but you are using the XPath 2.0 construct /a/b/concat('-', .). So I'm confused about what kind of XPath engine you are using. Commented Dec 4, 2023 at 17:06
  • XPath 1.0 already supports concat. w3.org/TR/1999/REC-xpath-19991116/#section-String-Functions Commented Dec 5, 2023 at 6:42
  • So yes, I use the xpath 1.0 engine. According to my link, XPath 1.0 already supports concat, and the linked post also refers to the Becker's method which is explained in an XPath 1.0 context. So I was quite comfortable to use concat as well. Am I wrong? Please correct me if I am! And if so, how can i tackle this problem with xpath 1.0? Commented Dec 5, 2023 at 7:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.