XSLT Transform for Gnucash XML file
Andreas Fromm
afromm at physik.uni-erlangen.de
Mon Sep 19 03:27:17 EDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Shouln'd this kind of work go to the wiki? There will surly be more
people intrested in.
Regards
Andreas.
Larry Evans wrote:
> On 09/05/2003 01:14 AM, Matthew Vanecek wrote:
>
>> I've written a simple XSLT transformation for the Gnucash XML
>> file. It spits out an HTML file with a 4-column table, "Account
>> Name", "Date Entered", "Number", "Descriptions", "Value". The
>> "Value" column values are preceded by an '='. This makes it easy
>> to import into OOo Calc, due to the way values are stored in our
>> XML file.
>
>
> Thanks Matthew,
>
> I've modified it to create a set of tables for each investment.
> Each table makes it fairly easy to calculate the average return on
> the investment. A simple modification of the stylesheet would make
> it ideal for use in gnumeric to do the actual calculations.
>
> The stylesheet is attached. Hopefully others will find it useful
> or modify it, like it did yours, to get exactly what they want.
>
>
>
> ----------------------------------------------------------------------
>
>
> <?xml version="1.0"?>
>
> <!-- Copyright (C) 2003 Matt Vanecek
>
> License is hereby granted to freely copy, modify, or distribute
> this work under the terms of the GNU General Public License, as
> found at http://www.gnu.org/licenses/gpl.html.
>
> ChangeLog: 2005-09-13 Larry Evans WHAT: 1) Downloaded from post at:
>
>
> http://article.gmane.org/gmane.comp.gnome.apps.gnucash.devel/10413
>
> and extracted .xsl file. 2) Renamed. 2005-09-18 Larry Evans WHAT:
> 1) Restricted accounts to those under "Investments" 2) Grouped
> accounts so each one had transactions table. 3) Added second table
> for account information, including latest commodity price. WHY:
> 1-3) To allow calculation of average return on investment for each
> investment from table information for that investment.
>
> -->
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:gnc="http://www.gnucash.org/XML/gnc"
> xmlns:cmdty="http://www.gnucash.org/XML/cmdty"
> xmlns:price="http://www.gnucash.org/XML/price"
> xmlns:act="http://www.gnucash.org/XML/act"
> xmlns:trn="http://www.gnucash.org/XML/trn"
> xmlns:split="http://www.gnucash.org/XML/split"
> xmlns:ts="http://www.gnucash.org/XML/ts"
> xmlns:cust="http://www.gnucash.org/XML/cust"
>
> <xsl:output method="html" indent="yes" encoding="ISO-8859-1"/>
>
> <xsl:template match="//gnc-v2/gnc:book"> <html>
> <head><title>Finances File</title></head> <body>
>
> <xsl:variable name="investments_id"> <xsl:value-of
> select="gnc:account[act:name='Investments']/act:id"/>
> </xsl:variable>
>
> <xsl:for-each select="gnc:account"> <xsl:sort select="act:name"/>
> <!-- Only select Investments accounts --> <xsl:if
> test="$investments_id=act:parent">
>
> <xsl:variable name="act_id"> <xsl:value-of select="act:id"/>
> </xsl:variable>
>
> <xsl:variable name="cmdty_id"> <xsl:value-of
> select="act:commodity/cmdty:id"/> </xsl:variable>
>
> <table border="1"> <caption>account information</caption>
>
> <th>name</th> <th>commodity</th> <th>Value</th> <th>on date</th>
> <tr> <td><xsl:value-of select="act:name"/></td> <td><xsl:value-of
> select="$cmdty_id"/></td> <td><xsl:value-of select=
> "../gnc:pricedb/price [ price:type='last' and
> price:commodity/cmdty:id=$cmdty_id ]/price:value " /> </td>
> <td><xsl:value-of select= "../gnc:pricedb/price [
> price:type='last' and price:commodity/cmdty:id=$cmdty_id
> ]/price:time " /> </td> </tr> </table>
>
> <table border="1"> <caption>account transactions</caption>
>
> <th>Date Posted</th> <th>Description</th> <th>Value</th>
> <th>Quantity</th>
>
> <xsl:for-each select="../gnc:transaction"> <xsl:sort
> select="trn:date-posted/ts:date"/>
>
> <xsl:if test="$act_id = trn:splits/trn:split/split:account"> <tr>
> <td><xsl:value-of
> select="substring(trn:date-posted/ts:date,1,10)"/></td>
> <td><xsl:value-of select="trn:description"/></td>
> <td>=<xsl:value-of select="trn:splits/trn:split/split:value"/></td>
> <td>=<xsl:value-of
> select="trn:splits/trn:split/split:quantity"/></td> </tr> </xsl:if>
> </xsl:for-each>
>
> </table> <HR size="5"/>
>
> </xsl:if>
>
> </xsl:for-each>
>
> </body> </html> </xsl:template>
>
> <!-- Root template - weed out the stuff we don't want -->
> <xsl:template match="text() | @*"> </xsl:template>
>
> </xsl:stylesheet>
>
>
> ----------------------------------------------------------------------
>
>
> _______________________________________________ gnucash-devel
> mailing list gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDLmhUUmBtSMq5cGURAtkdAKCFi4vEGcRIGuQPpSnegY6lV56tEACgq6rl
uJHjjHHTrEYYcWJGukNafos=
=LLtf
-----END PGP SIGNATURE-----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20050919/0e2b2de7/attachment.htm
More information about the gnucash-devel
mailing list