Dereconciling account using XSLT

Ben Pracht bpracht at nc.rr.com
Sun Apr 10 02:05:46 EDT 2005


After a couple of days of debugging and reading bad help on XSLT, I've 
discovered that
I had a namspace mismatch for the same nodes described in my stylesheet 
and the ones
I shoved into the GnuCash data file.

Anyway, I've worked the kinks out enough to get it to "listen" to me, 
and de-reconcile
my credit card account so that I can manually re-reconcile everything. 

If anyone else needs to retroactively add transactions to an account 
before the reconciled period, I'm including my stylesheet.  Of course 
study what it does and backup your file before you trust it, use 
caution, blah, blah. 

Not to developers:
It would have helped to have had:
*  A DTD for this file, locally available *without* getting the 
developers source copy, and without downloading off the web.
*  Namespace prefixes defined somewhere in the data file.
*  For that matter, cutting down on the namespaces to something like 
say, one, would be really nice.
*  Not used XML ever, but instead used an updatable database with 
documentation  on the tables, names, etc.  Ideally, the names in the DB 
would be easy enough to understand that documentation wouldn't be 
needed.  My XML file is 6.5mb, but I can compress it down to something 
substantially smaller than 1.44mb. 

My regards, best wishes, and sympathies for anyone else with 
reconciliation problems,
Ben

--- My crude, undocumented dereconciling stylesheet  ---

<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:gnc="gncns"
    xmlns:trn="trnns"
    xmlns:split="splitns"
    xmlns:cd="cdns"
    xmlns:book="bookns"
    xmlns:slot="slotns"
    xmlns:cmdty="cmdtyns"
    xmlns:act="actns"
    xmlns:ts="tsns"
    xmlns:sx="sxns"
    xmlns:fs="fsns"
    xmlns:vendor="vendorns"
    xmlns:addr="addrns">
    <xsl:output method="xml" indent="yes"/>

   <xsl:template match="/gnc-v2" priority="2">
       <gnc-v2 xmlns:gnc="gncns"
               xmlns:trn="trnns"
               xmlns:split="splitns"
               xmlns:cd="cdns"
               xmlns:book="bookns"
               xmlns:slot="slotns"
               xmlns:cmdty="cmdtyns"
               xmlns:act="actns"
               xmlns:ts="tsns"
               xmlns:sx="sxns"
               xmlns:fs="fsns"
               xmlns:vendor="vendorns"
               xmlns:addr="addrns">
               <xsl:apply-templates/>
       </gnc-v2>
   </xsl:template>


   <!-- Copy over the regular elements -->
   <xsl:template match="//*" priority="1">
        <xsl:variable 
name="cc_guid">02e9af78f313a8d28ae2b9ed7be04438</xsl:variable>
       <xsl:choose>
           <xsl:when test="name(.) = 'trn:split' and split:account = 
$cc_guid" >
               <xsl:call-template name="CC_SPLIT"/>
           </xsl:when>
           <xsl:otherwise>
               <xsl:call-template name="copyElement"/>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

   <xsl:template name="copyElement">
       <xsl:element name="{name(.)}">
           <xsl:for-each select="@*">
               <xsl:attribute name="{name()}">
                   <xsl:value-of select="."/>
               </xsl:attribute>
           </xsl:for-each>
           <xsl:apply-templates/>
       </xsl:element>
   </xsl:template>

   <!-- Copy over the comments -->
   <xsl:template match="//comment()" >
       <xsl:comment>
           <xsl:value-of select="."/>
       </xsl:comment>
   </xsl:template>

   <!-- Copy over the processing instructions -->
   <xsl:template match="//processing-instruction()" >
       <xsl:processing-instruction name="{name()}">
           <xsl:value-of select="."/>
       </xsl:processing-instruction>
   </xsl:template>

   <xsl:template name="CC_SPLIT">
       <trn:split>
           <xsl:copy-of select="split:id" />
           <split:reconciled-state>n</split:reconciled-state>
           <xsl:copy-of select="split:value"/>
           <xsl:copy-of select="split:quantity"/>
           <xsl:copy-of select="split:account"/>
       </trn:split>
   </xsl:template>

</xsl:stylesheet>



More information about the gnucash-user mailing list