Stupid Tricks With XSLT Round Trip transformations of GL Journal Entries in XSLT |
Todd Boyle CPA |
XSLT is a language for processing XML documents or data. Here is what small businesses need to understand about XSLT:
- An XSLT transformation, once designed, can potentially run on many different ecommerce platforms.
- XSLT transformations enable the users of different ecommerce standards and XML formats to interoperate, conducting business in their native XML languages through "translators".
- XSLT transformations can be run on the client computer or other locations, thus redistributing processing loads away from central servers.
- The speed of transformations doesn't matter much if you're only tranforming a few transactions. But large transformations such as your whole month's accounting data may be impractical.
2. General Ledger journal entries formatted in XML
Given the following example journal entries...
General Ledger Journal
Listing
example
July 2000 JournalNo. Date LineNo. Account Amount 8880 22/7/2000 101 10100 Cash in Bank Cr -3000 8880 22/7/2000 102 51200 Rent-Shop Dr 2000 8880 22/7/2000 103 51300 Rent-Office Dr 1000 8882 23/7/2000 107 10100 Cash in Bank Cr -2000 8882 23/7/2000 108 55200 Maintenance-Truck Dr 1500 8882 23/7/2000 109 55700 Maintenance-Auto Dr 500 8881 24/7/2000 104 12100 Accts Receivable Dr 6500 8881 24/7/2000 105 41100 Commissions income Cr -6500 Total Debits 11500 Total Credits 11500 |
Within a database or an XML file, Journal Entries (JEs) can always be
represented as a single table, i.e. having one row for each debit or credit as
you see above. Alternatively, JEs can be represented in two tables (for example
headers and lines). The above report could be reformatted
showing the journal numbers 8880, 8882,
etc. and the transaction dates on one line, and the line numbers
101,102, 103, etc. below. That is what we are going to do
to the data file in this example below.
It is possible to convert any given XML schema having a flatfile structure into a "normallized" structure having headers and
rows with an XSLT transformation, and vice versa.
The significance of these demo XSLT transformations is that they demonstrate it isn't critically important
which shape is chosen for an XML Schema standard, for transmitting General
Ledger data between different accounting systems, because they can be
reformatted by generic XSLT
transformations. (It is critically important, of course that there is some
agreement on the names of the data elements within the XML and XSLT files!)
3. Transformation of a hierarchic GL structure into a flat structure
Contents of 1st-Hierarchic2Flat zipfile
Hierarchic1.xml
Hie2Flat.xsl
Flatfile1.xml
Run1.bat
The file "Hierarchic1.xml" contains three general ledger journal entries, each having a header and two or more rows. i.e. the JEs are structured as hierarchies.
The file "Hie2Flat.xsl" is a generic XSL stylesheet that illustrates how a hierarchic file like a journal entry can be transformed into a flat structure, i.e., it converts the three GL JE's into eight rows, representing all of the debits and credits.
The XML file that results from the XSLT transformation is also included ("Flatfile1.xml"). However the intention of this tutorial is that you will use your own XSLT parser, such as XT or the XSLT-Helper HTML file, to execute the transformation yourself, and view the result. If you save the resulting file it should be the same as the "Flatfile.xml"
Run1.bat is a batchfile which executes the transformation using the command line, using James Taubers' "XT" utility,
Command syntax:
XT (source XML) (XSL sheet) (result XML)
XT Hierarchic1.xml Hie2Flat.xsl flatfile1.xml
See http://www.oasis-open.org/cover/xslSoftware.html#xt
Hierarchic XML source
file
4. Transformation of flat GL structure into a hierarchic structure
Contents of 2nd-Flat2Hierarchic zipfile:
Flatfile1.xml
Flat2hier.xsl
Hierarchic2.xml
The file "Flatfile1.xml" contains three general ledger journal entries, each having two or more rows. Each row of the general ledger listing contains a JEID identifying what journal entry it is associated with, and the JE Date.
The file "Flat2hier.xsl" is a generic XSL stylesheet that illustrates how a journal entry which is formatted in a flat structure can be transformed into a hierarchy consisting of a header, and child rows belonging to the header, i.e., it converts the eight Journal Entry rows representing all of the debits and credits into three GL JE's.
The XML file that results from the XSLT transformation is also included ("Hierarchic2.xml"). However the intention of this tutorial is that you will use your own XSLT parser, such as James Taubers' XT utility, to execute the transformation, and view the result in your own text editor. The resulting file should be the same as the enclosed "Hierarchic2.xml"
Run2.bat is a batchfile which executes the transformation using the command line, using James Taubers' "XT" utility,
Command syntax:
XT (source XML) (XSL sheet) (result XML)
XT flatfile1.xml Flat2hier.xsl Hierarchic2.xml
See http://www.oasis-open.org/cover/xslSoftware.html#xt
Flat XML source
file
Here are some references and tutorials. It is unrealistic to try learning XSLT without printing some of these on paper:
1. W3C XSLT http://www.w3.org/TR/xslt
2. W3C XPath language http://www.w3.org/TR/xpath
3. Chapter 14 of the XML Bible: XSL Transformations
http://metalab.unc.edu/xml/books/bible/updates/14.html
4. Grosso & Walsh tutorial http://www.nwalsh.com/docs/tutorials/xsl/xsl/slides.html
5. XSLT Alleviates. http://msdn.microsoft.com/msdnmag/issues/0800/XSLT/XSLT.asp
6. XSLT.com http://www.xslt.com