
<!--
/***************************************************************************
    begin       : Tue Nov 25 2025
    copyright   : (C) 2025 by Martin Preuss
    email       : martin@libchipcard.de

 ***************************************************************************
 *          Please see toplevel file COPYING for license details           *
 ***************************************************************************/
 
 This file can be used to import a CAMT.052.001.08 file.
 
-->

<Schema>

  <DocMatches>
    <Match path="Document@xmlns">*camt.052.001.08*</Match>
  </DocMatches>


  <Import>
 
    <XmlIfPathExists path="Document/BkToCstmrAcctRpt">
  
      <XmlEnter path="Document/BkToCstmrAcctRpt">
  
        <XmlForEvery name="Rpt">
  
          <DbCreateAndEnterGroup name="account">
  
            <XmlEnter path="Acct">
  
              <XmlIfHasCharData path="Id/IBAN">
                <DbSetCharValue name="iban" path="Id/IBAN"/>
              </XmlIfHasCharData>
  
              <XmlIfHasCharData path="Svcr/FinInstnId/BIC">
                <DbSetCharValue name="bic" path="Svcr/FinInstnId/BIC"/>
              </XmlIfHasCharData>
  
              <XmlIfHasCharData path="Ccy">
                <DbSetCharValue name="currency" path="Ccy"/>
              </XmlIfHasCharData>
            
            
            </XmlEnter>
  
  
            <XmlIfPathExists path="Bal">
              <XmlForEvery name="Bal">
      
                <DbCreateAndEnterGroup name="balance">
      
                  <!-- Type -->
                  <XmlIfCharDataMatches path="Tp/CdOrPrtry/Cd" pattern="CLBD">
                    <DbSetCharValue name="type" value="booked"/>
                  </XmlIfCharDataMatches>
                  
                  <XmlIfCharDataMatches path="Tp/CdOrPrtry/Cd" pattern="PRCD">
                    <DbSetCharValue name="type" value="booked"/>
                  </XmlIfCharDataMatches>
                  
                  <XmlIfCharDataMatches path="Tp/CdOrPrtry/Cd" pattern="CLAV">
                    <DbSetCharValue name="type" value="disposable"/>
                  </XmlIfCharDataMatches>
        
                  <!-- Date -->
                  <XmlIfHasCharData path="Dt/Dt">
                    <DbSetCharValue name="date" path="Dt/Dt" type="date" template="YYYY-MM-DD" />
                  </XmlIfHasCharData>
        
                  <!-- Amount -->
                  <XmlIfCharDataMatches path="CdtDbtInd" pattern="DBIT">
                    <!-- Debit -->
      
                    <XmlIfHasCharData path="Amt">
                      <XmlIfHasCharData path="Amt@Ccy">
                        <DbCreateAndEnterTempGroup name="amount" >
                          <DbSetTempCharValue name="value"    path="Amt" />
                          <DbSetTempCharValue name="currency" path="Amt@Ccy" />
                          <DbSetCharValue name="value" value="-$(value):$(currency)" />
                        </DbCreateAndEnterTempGroup> <!-- amount -->
                      </XmlIfHasCharData> <!-- Amt@Ccy -->
                    </XmlIfHasCharData>   <!-- Amt -->
      
                  </XmlIfCharDataMatches>
      
                  <XmlIfCharDataMatches path="CdtDbtInd" pattern="CRDT">
                    <!-- Credit -->
      
                    <XmlIfHasCharData path="Amt">
                      <XmlIfHasCharData path="Amt@Ccy">
                        <DbCreateAndEnterTempGroup name="amount" >
                          <DbSetTempCharValue name="value"    path="Amt" />
                          <DbSetTempCharValue name="currency" path="Amt@Ccy" />
                          <DbSetCharValue name="value" value="$(value):$(currency)" />
                        </DbCreateAndEnterTempGroup> <!-- amount -->
                      </XmlIfHasCharData> <!-- Amt@Ccy -->
                    </XmlIfHasCharData>   <!-- Amt -->
      
                  </XmlIfCharDataMatches>
        
        
                </DbCreateAndEnterGroup>
        
              </XmlForEvery>
            </XmlIfPathExists>
        
    
        
            <XmlForEvery name="Ntry">
    
             <XmlIfHasCharData path="Amt">
    
                <DbCreateAndEnterGroup name="transaction">

                  <!-- preset -->
                  <DbSetCharValue name="type" value="statement" />

                  <XmlIfCharDataMatches path="Sts/Cd" pattern="BOOK">
                    <DbSetCharValue name="type" value="statement" mode="replace" />
                  </XmlIfCharDataMatches>

                  <XmlIfCharDataMatches path="Sts/Cd" pattern="PDNG">
                    <DbSetCharValue name="type" value="notedStatement" mode="replace" />
                  </XmlIfCharDataMatches>
  
                  <!-- 
                    other status codes are:
                    INFO: only informational
                    FUTR: future (already in the books, but not in the users account)
                  -->
          
                  <!-- booking date -->
                  <XmlIfHasCharData path="BookgDt/Dt">
                    <DbSetCharValue name="date" path="BookgDt/Dt" type="date" template="YYYY-MM-DD" />
                  </XmlIfHasCharData>
          
          
                  <!-- valuta date -->
                  <XmlIfHasCharData path="ValDt/Dt">
                    <DbSetCharValue name="valutaDate" path="ValDt/Dt" type="date" template="YYYY-MM-DD" />
                  </XmlIfHasCharData>

                  <!-- bank reference -->
                  <XmlIfHasCharData path="AcctSvcrRef">
                    <DbSetCharValue name="bankReference" path="AcctSvcrRef"/>
                  </XmlIfHasCharData>

                  <!-- transaction key -->
                  <XmlIfPathExists path="BkTxCd/Domn">
                    <XmlEnter path="BkTxCd/Domn">
                        <DbCreateAndEnterTempGroup name="code" >
                          <DbSetTempCharValue name="code"    path="Cd" />
                          <DbSetTempCharValue name="family" path="Fmly/Cd" />
                          <DbSetTempCharValue name="subfamily" path="Fmly/SubFmlyCd" />
                          <DbSetCharValue     name="transactionKey" value="$(code)-$(family)-$(subfamily)" />
                        </DbCreateAndEnterTempGroup>
                    </XmlEnter> <!-- BkTxCd/Domn -->
                  </XmlIfPathExists>


                  <XmlIfPathExists path="NtryDtls/TxDtls">
                    <XmlEnter path="NtryDtls/TxDtls">

                      <!-- endToEndReference -->
                      <XmlIfHasCharData path="Refs/EndToEndId">
                        <DbSetCharValue name="endToEndReference" path="Refs/EndToEndId"/>
                      </XmlIfHasCharData>

                      <!-- mandateId -->
                      <XmlIfHasCharData path="Refs/MndtId">
                        <DbSetCharValue name="mandateId" path="Refs/MndtId"/>
                      </XmlIfHasCharData>

                      <!-- unique transaction id -->
                      <XmlIfCharDataMatches path="Refs/Prtry/Tp" pattern="FI-UMSATZ-ID">
                        <DbSetCharValue name="fiId" path="Refs/Prtry/Ref"/>
                      </XmlIfCharDataMatches>


                      <!-- local/remote name and account -->
                      <XmlIfCharDataMatches path="../../CdtDbtInd" pattern="DBIT">
                        <!-- Debit -->

                        <XmlIfPathExists path="RltdPties">
                          <XmlEnter path="RltdPties">
                            <XmlIfHasCharData path="Dbtr/Pty/Nm">
                              <DbSetCharValue name="localName" path="Dbtr/Pty/Nm"/>
                            </XmlIfHasCharData>

                            <XmlIfHasCharData path="DbtrAcct/Id/IBAN">
                              <DbSetCharValue name="localIban" path="DbtrAcct/Id/IBAN"/>
                            </XmlIfHasCharData>
                  
                            <XmlIfHasCharData path="Cdtr/Pty/Nm">
                              <DbSetCharValue name="remoteName" path="Cdtr/Pty/Nm"/>
                            </XmlIfHasCharData>
        
                            <XmlIfHasCharData path="CdtrAcct/Id/IBAN">
                              <DbSetCharValue name="remoteIban" path="CdtrAcct/Id/IBAN"/>
                            </XmlIfHasCharData>
                            
                            <XmlIfHasCharData path="UltmtCdtr/Pty/Nm">
                              <DbSetCharValue name="ultimateCreditor" path="UltmtCdtr/Pty/Nm"/>
                            </XmlIfHasCharData>
        
                            <XmlIfHasCharData path="UltmtDbtr/Pty/Nm">
                              <DbSetCharValue name="ultimateDebitor" path="UltmtDbtr/Pty/Nm"/>
                            </XmlIfHasCharData>
                        </XmlEnter> <!-- RltdPties -->
                      </XmlIfPathExists>
    
                      <XmlIfPathExists path="RltdAgts">
                        <XmlEnter path="RltdAgts">
                          <XmlIfHasCharData path="DbtrAgt/FinInstnId/BICFI">
                            <DbSetCharValue name="localBic" path="DbtrAgt/FinInstnId/BICFI"/>
                          </XmlIfHasCharData>

                          <XmlIfHasCharData path="CdtrAgt/FinInstnId/BICFI">
                            <DbSetCharValue name="remoteBic" path="CdtrAgt/FinInstnId/BICFI"/>
                          </XmlIfHasCharData>
                        </XmlEnter> <!-- RltdAgts -->
                      </XmlIfPathExists>

                        <XmlIfHasCharData path="Amt">
                          <XmlIfHasCharData path="Amt@Ccy">
                            <DbCreateAndEnterTempGroup name="amount" >
                              <DbSetTempCharValue name="value"    path="Amt" />
                              <DbSetTempCharValue name="currency" path="Amt@Ccy" />
                              <DbSetCharValue name="value" value="-$(value):$(currency)" />
                            </DbCreateAndEnterTempGroup> <!-- amount -->
                          </XmlIfHasCharData> <!-- Amt@Ccy -->
                        </XmlIfHasCharData>   <!-- Amt -->
                      
                      </XmlIfCharDataMatches> <!-- CdtDbtInd == DBIT -->
          
                  
                      <XmlIfCharDataMatches path="../../CdtDbtInd" pattern="CRDT">
                        <!-- Credit -->
              
                        <XmlIfPathExists path="RltdPties">
                          <XmlEnter path="RltdPties">

                            <XmlIfHasCharData path="Dbtr/Pty/Nm">
                              <DbSetCharValue name="remoteName" path="Dbtr/Pty/Nm"/>
                            </XmlIfHasCharData>
                            
                            <XmlIfHasCharData path="DbtrAcct/Id/IBAN">
                              <DbSetCharValue name="remoteIban" path="DbtrAcct/Id/IBAN"/>
                            </XmlIfHasCharData>
        
                            <XmlIfHasCharData path="Cdtr/Pty/Nm">
                              <DbSetCharValue name="localName" path="Cdtr/Pty/Nm"/>
                            </XmlIfHasCharData>
        
                            <XmlIfHasCharData path="CdtrAcct/Id/IBAN">
                              <DbSetCharValue name="localIban" path="CdtrAcct/Id/IBAN"/>
                            </XmlIfHasCharData>
          
                            <XmlIfHasCharData path="UltmtCdtr/Nm">
                              <DbSetCharValue name="ultimateCreditor" path="UltmtCdtr/Nm"/>
                            </XmlIfHasCharData>
        
                            <XmlIfHasCharData path="UltmtDbtr/Nm">
                              <DbSetCharValue name="ultimateDebitor" path="UltmtDbtr/Nm"/>
                            </XmlIfHasCharData>
    
                        </XmlEnter> <!-- RltdPties -->
                      </XmlIfPathExists>
              
                      <XmlIfPathExists path="RltdAgts">
                        <XmlEnter path="RltdAgts">
                          <XmlIfHasCharData path="CdtrAgt/FinInstnId/BICFI">
                            <DbSetCharValue name="localBic" path="CdtrAgt/FinInstnId/BICFI"/>
                          </XmlIfHasCharData>

                          <XmlIfHasCharData path="DbtrAgt/FinInstnId/BICFI">
                            <DbSetCharValue name="remoteBic" path="DbtrAgt/FinInstnId/BICFI"/>
                          </XmlIfHasCharData>
                        </XmlEnter> <!-- RltdAgts -->
                      </XmlIfPathExists>

                        <XmlIfHasCharData path="Amt">
                          <XmlIfHasCharData path="Amt@Ccy">
                            <DbCreateAndEnterTempGroup name="amount" >
                              <DbSetTempCharValue name="value"    path="Amt" />
                              <DbSetTempCharValue name="currency" path="Amt@Ccy" />
                              <DbSetCharValue name="value" value="$(value):$(currency)" />
                            </DbCreateAndEnterTempGroup> <!-- amount -->
                          </XmlIfHasCharData> <!-- Amt@Ccy -->
                        </XmlIfHasCharData>   <!-- Amt -->
          
                      </XmlIfCharDataMatches> <!-- CdtDbtInd == CRDT- -->
    
                      <!-- purpose lines -->
                      <XmlIfPathExists path="RmtInf">


                        <XmlEnter path="RmtInf">
                          <XmlIfHasCharData path="Ustrd"> <!-- ugly hack to avoid err msg -->
                            <XmlForEvery name="Ustrd">
                              <DbSetCharValue name="purpose" path="." mode="append" delimiter="\n"/>
                            </XmlForEvery>
                          </XmlIfHasCharData>
                        </XmlEnter> <!-- RmtInf -->
                      </XmlIfPathExists>
    
                    </XmlEnter>
                  </XmlIfPathExists>   <!-- NtryDtls/TxDtls -->
    
    
                  <!-- transaction text -->
                  <XmlIfHasCharData path="AddtlNtryInf">
                    <DbSetCharValue name="transactionText" path="AddtlNtryInf"/>
                  </XmlIfHasCharData>
                  
                </DbCreateAndEnterGroup> <!-- transaction --> 
             
             </XmlIfHasCharData> <!-- if there is an amount -->
    
            </XmlForEvery> <!-- Ntry -->

          </DbCreateAndEnterGroup> <!-- account -->
    
        </XmlForEvery>   <!-- Rpt -->
      
      </XmlEnter> <!-- Document/BkToCstmrAcctRpt -->
  
    </XmlIfPathExists> <!-- Document/BkToCstmrAcctRpt -->
  
  </Import>


</Schema>

