Last active
December 27, 2015 08:59
-
-
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".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"/>/<xsl:value-of select="$mo"/>/<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> </td> | |
</xsl:otherwise> | |
</xsl:choose> | |
<td><xsl:value-of select="TRNAMT"/> <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