Hi folks! For personnal usage, I've written a translator from gnucash-XML into OFX files to import them under Microsoft Money.
I don't think I will personaly look a long more in this direction, but it could be interessant for the gnucash-developement team, can't it? More information will you find in the two enclosed files. Don't hesitate to mail me or write me on this list to have more details. Olivier
<!-- XSL-Code to transform a Gnucash XML file into QIF.
Aim is to be able to import the QIF file into Microsoft Money 2004 (american).
For more explanations, see the README too.
November 2003, Olivier Faucheux (olivier at faucheux dot eu dot org)
-->
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- I don't kwon the adresses for namespaces, but the parser of Microsoft Internet Explorer
requires something here. -->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gnc="http://unknow"
xmlns:act="http://unknow"
xmlns:cmdty="http://unknow"
xmlns:slot="http://unknow"
xmlns:trn="http://unknow"
xmlns:ts="http://unknow"
xmlns:split="http://unknow"
xmlns:cd="http://unknow" >
<!-- Not sure its the good output format. But it works for what I wanted to do.
If I use something else, not all the text is displayed -->
<xsl:output method="html" indent="no" standalone="yes" media-type="text/plain"/>
<xsl:template match="gnc-v2">
<!-- Write the list of accounts. Because Microsoft Money doesn't know the
double-part accounting, only "bank" accounts are exported: BANK, CREDIT, STOCK
and CASH. This list should surely be extented -->
<xsl:text disable-output-escaping="no">!Account</xsl:text><br />
<xsl:apply-templates select="//gnc:account[act:type='BANK'
or act:type='CREDIT'
or act:type = 'STOCK'
or act:type='CASH']"
mode="Account"/>
<!-- Write for each of this accounts its transactions -->
<xsl:apply-templates select="//gnc:account[act:type='BANK'
or act:type='CREDIT'
or act:type = 'STOCK'
or act:type='CASH']"
mode="Bank">
<xsl:sort select="act:name" />
</xsl:apply-templates>
</xsl:template>
<!-- Template to write the information concerning one account -->
<xsl:template match="gnc:account" mode="Account">
<!-- Name of the account -->
<xsl:text disable-output-escaping="no">N</xsl:text>
<xsl:value-of select="act:name" />
<br />
<!-- Type of the account. Because Money doesn't accept things like 'CREDIT',
I always write Bank. It should be corrected, but not any piece of good
documentation for QIF exists -->
<xsl:text disable-output-escaping="no">T</xsl:text>
<xsl:text disable-output-escaping="no">Bank</xsl:text>
<!-- <xsl:value-of select="act:type" /> -->
<br />
<!-- End of information for this account -->
<xsl:text disable-output-escaping="no">^</xsl:text>
<br />
</xsl:template>
<!-- Template to export the transactions concerning one particular account. -->
<xsl:template match="gnc:account" mode="Bank">
<!-- QIF !Type:Bank keyword to signal Money we are listing transactions for
a new account -->
<xsl:text disable-output-escaping="no">!Type:Bank</xsl:text><br />
<xsl:variable name="accountID" select="act:id/text()" />
<xsl:apply-templates select="//trn:split[split:account=$accountID]">
<xsl:with-param name="AccountID" select="$accountID" />
</xsl:apply-templates>
</xsl:template>
<!-- Template to export one transaction
1) Splited transactions (transactions which more than 2 accounts) aren't good exported for the time
2) We have to export each transaction only once. To garantee that,
I test before exporting an <gnc:transaction> that the current account
is the first "bank" account for this transaction -->
<xsl:template match="trn:split">
<xsl:param name='AccountID' select='//..' />
<!-- Look after a preceding split for a bank account. If found, the transaction will be exported
for this accound and shouldn't be exported here. -->
<xsl:variable name="otherAccountTypes" select="//gnc:account[act:id/text() = current()/preceding-sibling::trn:split/split:account/text()]/act:type[.='BANK' or .='CREDIT' or .='CASH' or .='STOCK']" />
<xsl:if test="not($otherAccountTypes)">
<!-- Date of the transaction -->
<xsl:text disable-output-escaping="no">D</xsl:text>
<xsl:value-of select="substring(../../trn:date-posted/ts:date,9,2)"/>
<xsl:text disable-output-escaping="no">/</xsl:text>
<xsl:value-of select="substring(../../trn:date-posted/ts:date,6,2)"/>
<xsl:text disable-output-escaping="no">'</xsl:text>
<xsl:value-of select="substring(../../trn:date-posted/ts:date,1,4)"/>
<br />
<!-- Amount of the transaction (Credit or debit for the current account) -->
<xsl:text disable-output-escaping="no">T</xsl:text>
<xsl:value-of select="number(substring-before(split:quantity,'/')) div 100"/>
<br />
<!-- Text description of the transaction -->
<xsl:text disable-output-escaping="no">P</xsl:text>
<xsl:value-of select="substring(../../trn:description,1,32)" disable-output-escaping="no"/>
<br />
<!-- Transfert unique -->
<!-- Other credited/debited account -->
<xsl:text disable-output-escaping="no">L</xsl:text>
<xsl:variable name='otherAccountID' select='../trn:split/split:account[text() != $AccountID]' />
<xsl:variable name='otherAccount' select='/gnc-v2/gnc:account[act:id = $otherAccountID]' />
<!-- Money distinguishes accounts and categories. Accounts have to be written "[Postbank]" and
categories simply "Food" -->
<xsl:choose>
<xsl:when test="$otherAccount/act:type = 'BANK'
or $otherAccount/act:type = 'STOCK'
or $otherAccount/act:type = 'CASH'
or $otherAccount/act:type = 'CREDIT'">
<xsl:text disable-output-escaping="no">[</xsl:text>
<xsl:value-of select="$otherAccount/act:name" disable-output-escaping="no"/>
<xsl:text disable-output-escaping="no">]</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$otherAccount/act:name" disable-output-escaping="no"/>
</xsl:otherwise>
</xsl:choose>
<br />
<!-- End of the transaction -->
<xsl:text disable-output-escaping="no">^</xsl:text>
<br />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<!--- vim:set ts=2: -->
README
Description: Binary data
_______________________________________________ gnucash-devel mailing list [EMAIL PROTECTED] http://www.gnucash.org/cgi-bin/mailman/listinfo/gnucash-devel
