-
Notifications
You must be signed in to change notification settings - Fork 2
/
camt2ofx.xsl
145 lines (124 loc) · 5.5 KB
/
camt2ofx.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:camt="urn:iso:std:iso:20022:tech:xsd:camt.053.001.04" exclude-result-prefixes="camt">
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
<!-- Look at the file's GrpHdr -->
<xsl:template match="/camt:Document/camt:BkToCstmrStmt/camt:GrpHdr">
<!-- Check if the camt 053 statement is contained within a single file/message
We don't handle statements split into multiple files yet
and if one is encountered, the translation will be aborted -->
<xsl:if test="camt:MsgPgntn/camt:PgNb != 1 or camt:MsgPgntn/camt:LastPgInd != 'true'">
<xsl:message terminate="yes">
<xsl:text>Incomplete message (not first page or subsequent pages exist)</xsl:text>
</xsl:message>
</xsl:if>
</xsl:template>
<!-- Handle one of the summary rows (opening or closing balance details) -->
<xsl:template match="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Bal">
<BALAMT>
<xsl:if test="camt:CdtDbtInd != 'CRDT'">-</xsl:if><xsl:value-of select="camt:Amt"/>
</BALAMT>
<DTASOF>
<xsl:value-of select="translate(camt:Dt/camt:Dt,'-','')"/>
</DTASOF>
</xsl:template>
<!-- Handle one of the entries in the list of transactions -->
<xsl:template match="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Ntry">
<xsl:variable name="fee" select="translate(number(camt:Chrgs/camt:TtlChrgsAndTaxAmt), 'aN', '0')"/>
<STMTTRN>
<TRNTYPE>
<xsl:if test="camt:CdtDbtInd = 'CRDT'">CREDIT</xsl:if>
<xsl:if test="camt:CdtDbtInd = 'DBIT'">DEBIT</xsl:if>
</TRNTYPE>
<DTPOSTED>
<xsl:value-of select="translate(camt:ValDt/camt:Dt,'-','')"/>
</DTPOSTED>
<TRNAMT>
<xsl:if test="camt:CdtDbtInd != 'CRDT'">-</xsl:if><xsl:value-of select="camt:Amt - $fee"/>
</TRNAMT>
<FITID>
<xsl:value-of select="camt:NtryDtls/camt:TxDtls/camt:Refs/camt:AcctSvcrRef"/>
</FITID>
<NAME>
<xsl:value-of select="camt:NtryDtls/camt:TxDtls/camt:RltdPties/camt:Cdtr/camt:Nm"/>
<xsl:value-of select="camt:NtryDtls/camt:TxDtls/camt:RltdPties/camt:Dbtr/camt:Nm"/>
</NAME>
<MEMO>
<xsl:value-of select="camt:AddtlNtryInf"/>
</MEMO>
</STMTTRN>
<xsl:if test="$fee > 0">
<STMTTRN>
<TRNTYPE>FEE</TRNTYPE>
<DTPOSTED>
<xsl:value-of select="translate(camt:ValDt/camt:Dt,'-','')"/>
</DTPOSTED>
<TRNAMT><xsl:value-of select="-$fee"/>
</TRNAMT>
<FITID>
<xsl:value-of select="camt:NtryDtls/camt:TxDtls/camt:Refs/camt:AcctSvcrRef"/><xsl:text>/FEE</xsl:text>
</FITID>
<NAME>
<xsl:value-of select="camt:NtryDtls/camt:TxDtls/camt:RltdPties/camt:Cdtr/camt:Nm"/>
</NAME>
<MEMO>
<xsl:value-of select="camt:AddtlNtryInf"/>
</MEMO>
</STMTTRN>
</xsl:if>
</xsl:template>
<!-- Handle the root node of the XML document -->
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><?OFX OFXHEADER="200" VERSION="202" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>
</xsl:text>
<OFX>
<BANKMSGSRSV1>
<STMTTRNRS>
<STMTRS>
<TRNUID>
<xsl:value-of select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Id"/>
</TRNUID>
<CURDEF>
<xsl:value-of select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Bal/camt:Amt/@Ccy"/>
</CURDEF>
<BANKACCTFROM>
<BANKID>
<xsl:value-of select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Acct/camt:Svcr/camt:FinInstnId/camt:BICFI"/>
</BANKID>
<ACCTID>
<xsl:value-of select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Acct/camt:Id"/>
</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>
<xsl:value-of select="translate(/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Bal/camt:Tp/camt:CdOrPrtry/camt:Cd[text()='OPBD']/../../../camt:Dt/camt:Dt,'-','')"/>
</DTSTART>
<DTEND>
<xsl:value-of select="translate(/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Bal/camt:Tp/camt:CdOrPrtry/camt:Cd[text()='CLBD']/../../../camt:Dt/camt:Dt,'-','')"/>
</DTEND>
<!-- List of transaction details -->
<xsl:apply-templates select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Ntry"/>
</BANKTRANLIST>
<LEDGERBAL>
<!-- Closing balance -->
<xsl:apply-templates select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Bal/camt:Tp/camt:CdOrPrtry/camt:Cd[text()='CLBD']/../../.."/>
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>
<!-- Check the GrpHdr first
<xsl:apply-templates select="/camt:Document/camt:BkToCstmrStmt/camt:GrpHdr"/>
-->
<!-- Closing balance
/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Bal/camt:Tp/camt:CdOrPrtry/camt:Cd[text()='CLBD']/../../..
/camt:Dt/camt:Dt
<xsl:value-of select="camt:Dt/camt:Dt"/>
<xsl:if test="camt:CdtDbtInd != 'CRDT'">-</xsl:if><xsl:value-of select="camt:Amt"/>
-->
<!-- Account holder name
<xsl:value-of select="/camt:Document/camt:BkToCstmrStmt/camt:Stmt/camt:Acct/camt:Ownr/camt:Nm"/>
-->
</xsl:template>
</xsl:stylesheet>