Gnucash XML Data File XSLT Transformation steps

Matthew Vanecek mevanecek at yahoo.com
Mon Aug 11 00:03:18 CDT 2003


Jon,

Can you include this in the documentation?  

The Gnucash XML data file can be tranformed to almost any other data
format (e.g., QIF, CSV...) quite easily if one is familiar with XSLT. 
The Gnucash data file is well-formed XML, and it can therefore be run
through an XSLT parser with an associated stylesheet.  This allows one
to transform the file to just about any format that can be designed,
given a properly written stylesheet.

A few steps need to be followed.  The writing of a stylesheet is a task
for a different time, but if you can get one written, here's what you
need to do:

1) Copy the Gnucash to a working file.  Modify the working file's
<gnc-v2> tag to read something like what's below.  Note that you can
pretty much put anything you want in the '="..."' part; I used the URL
because it's traditional (if such can be said about such a young
technology!).

<gnc-v2 xmlns:cd="http://www.gnucash.org/XML/cd"
        xmlns:book="http://www.gnucash.org/XML/book"
        xmlns:gnc="http://www.gnucash.org/XML/gnc"
        xmlns:cmdty="http://www.gnucash.org/XML/cmdty"
        xmlns:trn="http://www.gnucash.org/XML/trn"
        xmlns:split="http://www.gnucash.org/XML/split"
        xmlns:act="http://www.gnucash.org/XML/act"
        xmlns:price="http://www.gnucash.org/XML/price"
        xmlns:ts="http://www.gnucash.org/XML/ts"
        xmlns:slot="http://www.gnucash.org/XML/kvpslot"
        xmlns:cust="http://www.gnucash.org/XML/cust"
        xmlns:addr="http://www.gnucash.org/XML/custaddr">

2) Create an XSLT stylesheet containing the transformation your desire,
or obtain one that's already written (AFAIK, there aren't any, but I'm
working on a CSV one).

3) Install an XSLT processor such as Saxon
(http://saxon.sourceforge.net/) or Xalan-J  (http://xml.apache.org/). 
Any conforming processor will do, really...

4) Run the work file and the stylesheet through the processor according
to the processor's instructions.

5) You will now have a file in the desired output format.  An
enterprising individual could go so far as to write a stylesheet to
transform the Gnucash data file to an OpenOffice spreadsheet (or
vice-versa, for that matter).  Such things as QIF ought to be a little
less work.

Benefits are that you don't need to write a Scheme module or a new C
routine to do this transformation.  Anyone who knows or can learn XML
and XSLT can perform this task.  Not much harder, really, than writing a
Web page....

Anyhow, I just wanted this tidbit to be captured somewhere permanently. 
I know the process works on 1.8.4 and CVS HEAD datafiles, and ought to
work on earlier 1.8.x versions, too.  Haven't mucked with 1.6.x in a
while, but it *should* work there, too...

-- 
Matthew Vanecek
perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
********************************************************************************
For 93 million miles, there is nothing between the sun and my shadow except me.
I'm always getting in the way of something...



More information about the gnucash-devel mailing list