Export from GnuCash to Gnumeric

Zach Garner zach@neurosoft.org
23 Feb 2002 17:31:56 -0600


--=-HLxx/lV9nNS3lNUFDx+W
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I have spent a couple hours learning some XML and hacked an XSL file to
convert from a GnuCash Account file to a Gnumeric spreadsheet. It is
very rough at this point. Downloaded it at
http://www.neurosoft.org/gnucash/gnumeric_xsl or get it from the
attachment.

A couple of obvious (and major) problems:
1. Gnucash does not define its Namespaces properly. For XSL to work, you
have to edit the Account file, and change <gnc-v2> to:
  <gnc-v2 xmlns:act="http://www.gnucash.org/act"
        xmlns:gnc="http://www.gnucash.org/gnc"
        xmlns:trn="http://www.gnucash.org/trn"
        xmlns:ts="http://www.gnucash.org/ts"
        xmlns:split="http://www.gnucash.org/split">

These are just bogus values. The Gnucash project needs to properly
define the namespaces.

2. I haven't been able to properly connect the Account Name and the
Account ID within the spreadsheet. This causes the transactions to be
listed by the ID instead of by the name.

3. I do not know how to process the Date field with XSL or Gnumeric.
Gnumeric considers it a String because of the Timezone information.

---------

To use with Apache Xalan, execute
  $ java org.apache.xalan.xslt.Process -in Accounts.gnucash -xsl
gnumeric.xsl -out Accounts.gnumeric


Suggestions/Criticism/etc welcome.

--
Zach Garner



--=-HLxx/lV9nNS3lNUFDx+W
Content-Disposition: attachment; filename=gnumeric.xsl
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

<!--
  - Copyright (c) 2002 Zach Garner.  All rights reserved.
  -=20
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions
  - are met:
  - 1. Redistributions of source code must retain the above copyright
  -    notice, this list of conditions and the following disclaimer.
  - 2. Redistributions in binary form must reproduce the above copyright
  -    notice, this list of conditions and the following disclaimer in the
  -    documentation and/or other materials provided with the distribution.
  - 3. All advertising materials mentioning features or use of this softwar=
e
  -    must display the following acknowledgement:
  -      This product includes software developed by the University of
  -      California, Berkeley and its contributors.
  - 4. Neither the name of the University nor the names of its contributors
  -    may be used to endorse or promote products derived from this softwar=
e
  -    without specific prior written permission.
  -=20
  - THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
  - ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABL=
E
  - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
  - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
  - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
  - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - SUCH DAMAGE.
 -->

<?xml version=3D"1.0"?>
<xsl:stylesheet version=3D"1.0"
	xmlns:gnc=3D"http://www.gnucash.org/gnc"
	xmlns:act=3D"http://www.gnucash.org/act"
        xmlns:trn=3D"http://www.gnucash.org/trn"
        xmlns:ts=3D"http://www.gnucash.org/ts"
        xmlns:split=3D"http://www.gnucash.org/split"
	xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform">

<xsl:output indent=3D"yes"/>

<xsl:template match=3D"/">
<gmr:Workbook xmlns:gmr=3D"http://www.gnumeric.org/v10.dtd" xmlns:xsi=3D"ht=
tp://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=3D"http://www.g=
numeric.org/v8.xsd">
  <gmr:Attributes>
    <gmr:Attribute>
      <gmr:name>WorkbookView::show_horizontal_scrollbar</gmr:name>
      <gmr:type>4</gmr:type>
      <gmr:value>TRUE</gmr:value>
    </gmr:Attribute>
    <gmr:Attribute>
      <gmr:name>WorkbookView::show_vertical_scrollbar</gmr:name>
      <gmr:type>4</gmr:type>
      <gmr:value>TRUE</gmr:value>
    </gmr:Attribute>
    <gmr:Attribute>
      <gmr:name>WorkbookView::show_notebook_tabs</gmr:name>
      <gmr:type>4</gmr:type>
      <gmr:value>TRUE</gmr:value>
    </gmr:Attribute>
    <gmr:Attribute>
      <gmr:name>WorkbookView::do_auto_completion</gmr:name>
      <gmr:type>4</gmr:type>
      <gmr:value>TRUE</gmr:value>
    </gmr:Attribute>
  </gmr:Attributes>
  <gmr:Summary>
    <gmr:Item>
      <gmr:name>application</gmr:name>
      <gmr:val-string>gnumeric</gmr:val-string>
    </gmr:Item>
    <gmr:Item>
      <gmr:name>author</gmr:name>
      <gmr:val-string>Zach Garner</gmr:val-string>
    </gmr:Item>
  </gmr:Summary>
  <gmr:SheetNameIndex>
    <gmr:SheetName>Sheet1</gmr:SheetName>
  </gmr:SheetNameIndex>
  <gmr:Names/>
  <gmr:Geometry Width=3D"1166" Height=3D"746"/>
  <gmr:Sheets>
    <gmr:Sheet DisplayFormulas=3D"false" HideZero=3D"false" HideGrid=3D"fal=
se" HideColHeader=3D"false" HideRowHeader=3D"false" DisplayOutlines=3D"true=
" OutlineSymbolsBelow=3D"true" OutlineSymbolsRight=3D"true">
      <gmr:Name>Sheet1</gmr:Name>
      <gmr:MaxCol>1</gmr:MaxCol>
      <gmr:MaxRow>0</gmr:MaxRow>
      <gmr:Zoom>1.000000</gmr:Zoom>
      <gmr:Names/>
      <gmr:PrintInformation>
        <gmr:Margins>
          <gmr:top Points=3D"28.3" PrefUnit=3D"cm"/>
          <gmr:bottom Points=3D"28.3" PrefUnit=3D"cm"/>
          <gmr:left Points=3D"28.3" PrefUnit=3D"cm"/>
          <gmr:right Points=3D"28.3" PrefUnit=3D"cm"/>
          <gmr:header Points=3D"14.2" PrefUnit=3D"cm"/>
          <gmr:footer Points=3D"14.2" PrefUnit=3D"cm"/>
        </gmr:Margins>
        <gmr:Scale type=3D"percentage" percentage=3D"100"/>
        <gmr:vcenter value=3D"0"/>
        <gmr:hcenter value=3D"0"/>
        <gmr:grid value=3D"0"/>
        <gmr:even_if_only_styles value=3D"0"/>
        <gmr:monochrome value=3D"0"/>
        <gmr:draft value=3D"0"/>
        <gmr:titles value=3D"0"/>
        <gmr:repeat_top value=3D""/>
        <gmr:repeat_left value=3D""/>
        <gmr:order>r_then_d</gmr:order>
        <gmr:orientation>landscape</gmr:orientation>
        <gmr:Header Left=3D"" Middle=3D"&amp;[TAB]" Right=3D""/>
        <gmr:Footer Left=3D"" Middle=3D"Page &amp;[PAGE]" Right=3D""/>
        <gmr:paper>A4</gmr:paper>
      </gmr:PrintInformation>
      <gmr:Styles>
        <gmr:StyleRegion startCol=3D"0" startRow=3D"0" endCol=3D"255" endRo=
w=3D"65535">
          <gmr:Style HAlign=3D"1" VAlign=3D"2" WrapText=3D"0" Orient=3D"1" =
Shade=3D"0" Indent=3D"0" Locked=3D"1" Hidden=3D"0" Fore=3D"0:0:0" Back=3D"F=
FFF:FFFF:FFFF" PatternColor=3D"0:0:0" Format=3D"General">
            <gmr:Font Unit=3D"9" Bold=3D"0" Italic=3D"0" Underline=3D"0" St=
rikeThrough=3D"0">Helvetica</gmr:Font>
            <gmr:StyleBorder>
              <gmr:Top Style=3D"0"/>
              <gmr:Bottom Style=3D"0"/>
              <gmr:Left Style=3D"0"/>
              <gmr:Right Style=3D"0"/>
              <gmr:Diagonal Style=3D"0"/>
              <gmr:Rev-Diagonal Style=3D"0"/>
            </gmr:StyleBorder>
          </gmr:Style>
        </gmr:StyleRegion>
      </gmr:Styles>
      <gmr:Cols DefaultSizePts=3D"48">
        <gmr:ColInfo No=3D"0" Unit=3D"48" MarginA=3D"2" MarginB=3D"2" Count=
=3D"2"/>
      </gmr:Cols>
      <gmr:Rows DefaultSizePts=3D"12.8">
        <gmr:RowInfo No=3D"0" Unit=3D"12.8" MarginA=3D"1" MarginB=3D"0"/>
      </gmr:Rows>
      <gmr:Selections CursorCol=3D"1" CursorRow=3D"7">
        <gmr:Selection startCol=3D"1" startRow=3D"7" endCol=3D"1" endRow=3D=
"7"/>
      </gmr:Selections>
      <gmr:Cells>
	<xsl:apply-templates/>
      </gmr:Cells>
      <gmr:SheetLayout TopLeft=3D"A1"/>
      <gmr:Solver TargetCol=3D"-1" TargetRow=3D"-1" ProblemType=3D"1" Input=
s=3D""/>
    </gmr:Sheet>
  </gmr:Sheets>
  <gmr:UIData SelectedTab=3D"0"/>
</gmr:Workbook>

</xsl:template>

<xsl:template match=3D"gnc-v2">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match=3D"gnc:count-data">
</xsl:template>

<!-- output comma delimited account information -->
<xsl:template match=3D"gnc:account">
	<gmr:Cell Col=3D"5" ValueType=3D"60"><xsl:attribute name=3D"Row"><xsl:numb=
er level=3D"any"/></xsl:attribute><xsl:value-of select=3D"act:name"/></gmr:=
Cell>
	<gmr:Cell Col=3D"6" ValueType=3D"60"><xsl:attribute name=3D"Row"><xsl:numb=
er level=3D"any"/></xsl:attribute><xsl:value-of select=3D"act:type"/></gmr:=
Cell>
	<gmr:Cell Col=3D"7" ValueType=3D"60"><xsl:attribute name=3D"Row"><xsl:numb=
er level=3D"any"/></xsl:attribute><xsl:value-of select=3D"act:id"/></gmr:Ce=
ll>
</xsl:template>


<xsl:template match=3D"gnc:transaction">
	<xsl:for-each select=3D"trn:splits/trn:split">
		<gmr:Cell Col=3D"0" ValueType=3D"60"><xsl:attribute name=3D"Row"><xsl:num=
ber level=3D"any"/></xsl:attribute><xsl:value-of select=3D"../../trn:date-p=
osted/ts:date"/></gmr:Cell>
		<gmr:Cell Col=3D"1" ValueType=3D"60"><xsl:attribute name=3D"Row"><xsl:num=
ber level=3D"any"/></xsl:attribute><xsl:value-of select=3D"../../trn:descri=
ption"/></gmr:Cell>
		<gmr:Cell Col=3D"2"><xsl:attribute name=3D"Row"><xsl:number level=3D"any"=
/></xsl:attribute>=3D<xsl:value-of select=3D"split:value"/></gmr:Cell>
		<gmr:Cell Col=3D"3" ValueType=3D"60"><xsl:attribute name=3D"Row"><xsl:num=
ber level=3D"any"/></xsl:attribute><xsl:value-of select=3D"split:account"/>=
</gmr:Cell>
	</xsl:for-each>
</xsl:template>



</xsl:stylesheet>

--=-HLxx/lV9nNS3lNUFDx+W--