Skip to content

Instantly share code, notes, and snippets.

@petri
Last active December 27, 2015 08:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petri/7300330 to your computer and use it in GitHub Desktop.
Save petri/7300330 to your computer and use it in GitHub Desktop.
XSLT stylesheet for displaying OFX statements. Use with xsltproc, for example "xsltproc transform.xslt statements.ofx > statements.html".
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- convert dates to yyyy/mm/dd -->
<xsl:template match="DTPOSTED">
<xsl:variable name="yr" select="substring(current(),1,4)"/>
<xsl:variable name="mo" select="substring(current(),5,2)"/>
<xsl:variable name="dt" select="substring(current(),7,2)"/>
<xsl:value-of select="$yr"/>&#47;<xsl:value-of select="$mo"/>&#47;<xsl:value-of select="$dt"/>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="currency">
<xsl:value-of select="OFX/BANKMSGSRSV1/STMTTRNRS/STMTRS/CURDEF"/>
</xsl:variable>
<xsl:variable name="begindate">
<xsl:apply-templates select="OFX/BANKMSGSRSV1/STMTTRNRS/STMTRS/BANKTRANLIST/STMTTRN[1]/DTPOSTED"/>
</xsl:variable>
<xsl:variable name="enddate">
<xsl:apply-templates select="OFX/BANKMSGSRSV1/STMTTRNRS/STMTRS/BANKTRANLIST/STMTTRN[last()]/DTPOSTED"/>
</xsl:variable>
<html>
<body>
<h2>Statements <xsl:value-of select="$begindate"/>-<xsl:value-of select="$enddate"/></h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Date</th>
<th>Type</th>
<th>Payee/Recipient</th>
<th>Amount</th>
<th>Reference</th>
<th>Memo</th>
</tr>
<xsl:for-each select="OFX/BANKMSGSRSV1/STMTTRNRS/STMTRS/BANKTRANLIST/STMTTRN">
<tr>
<td><xsl:apply-templates select="DTPOSTED"/></td>
<td><xsl:value-of select="TRNTYPE"/></td>
<!-- display either PAYEE or NAME - if neither exists, add empty placeholder -->
<xsl:choose>
<xsl:when test="PAYEE">
<td><xsl:value-of select="PAYEE"/></td>
</xsl:when>
<xsl:when test="NAME">
<td><xsl:value-of select="NAME"/></td>
</xsl:when>
<xsl:otherwise>
<td>&#160;</td>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="TRNAMT"/>&#160;<xsl:value-of select="$currency"/></td>
<td><xsl:value-of select="REFNUM"/></td>
<td><xsl:value-of select="MEMO"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment