codeBlog
Definately beta v0.9


Language: EN | FI

I just finished rather tedious bit of work turning my XML to HTML XSLT routine to XML to RTF one. Why? Well I think I made bit of a miscalculation on my part when I thought that HTML files would be good enough for printing invoices. Although they're ok when there's like one invoice to print but printing many is not going to work so easily, for one pagination is rather difficult as are font-sizes and every other crap. So I have this piece of software that outputs invoices as XML and I really didn't want to start tinkering the code, which by the way is done on C#, so the support for XSLT 2.0 was pretty much ruled out. Hate C# but for usability's sake I handed my pinky for the devil.

I wanted to create on A4 per tenant containing years worth of payments, naturally If I'd been able to use XSLT 2.0 this would have been done like 4 hours ago, seeming that XML produced was like:

<invoices>
<invoice>
</invoice>
<tenant>
<amountToPay>
<etc..>
</invoice>


So I'd just used the group-by function to to group same tenant's invoices together and formed the one A4 invoice that way, but no I just had to knife it out, the code I mean. So I refactored the XML to be produced like:

<invoice>
<invoice>
<tenant>
<totalAmountToPay>
<monthlyPayments>
<amount>
<dueDate>
</monthlyPayments>
<monthlyPayments>
<amount>
<dueDate>
</monthlyPayments>
<monthlyPayments>
<amount>
<dueDate>
</monthlyPayments>
</invoice>
</invoices>

So problem solved, Although the XML to RTF conversion proved to be somewhat difficult, I had to look out for how RTF documents are built and then create a XSLT stylesheet to accommodate that. so it ended up looking like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform lasku_11-3-2008.xsd">
    <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/laskut">
        <xsl:text>{\rtf1\UTF-8</xsl:text>
        <xsl:text>{\fonttbl{\f0\fnil Times New Roman;}{\f1\fnil Arial;}{\f2\fnil Symbol;}{\f3\fnil Wingdings;}}</xsl:text>
        <xsl:for-each select="lasku" xml:space="default">
            <xsl:text>{\pard \b Vastikelasku \par}</xsl:text>
            <xsl:text>{\pard AS. OY Koukkukallio \line Tiliyhteys: 207438-1654 \par} \line </xsl:text>
            <xsl:text>{\pard \b Maksaja: \par}</xsl:text>
            <xsl:text>{\pard </xsl:text><xsl:value-of select="nimi1"/><xsl:text> \par}</xsl:text>
            <xsl:text>{\pard </xsl:text><xsl:value-of select="nimi2"/><xsl:text> \par}</xsl:text>
            <xsl:text>{\pard </xsl:text><xsl:value-of select="osoite"/><xsl:text> \par}</xsl:text>
            <xsl:text>{\pard </xsl:text><xsl:value-of select="postinro"/><xsl:text> \par}</xsl:text>
            <xsl:text>{\pard </xsl:text><xsl:value-of select="kaupunki"/><xsl:text> \par} \line</xsl:text>
           
            <xsl:text>{\pard \b Erittely: \par}</xsl:text>
            <xsl:if test="vastike != '0,00'">
            <xsl:text>{\pard \qj Vastikemaksu:        </xsl:text><xsl:value-of select="vastike"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:if test="rahoitusvastike != '0,00'">
            <xsl:text>{\pard \qj Rahoitusvastike:    </xsl:text><xsl:value-of select="rahoitusvastike"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:if test="saunavastike != '0,00'">
            <xsl:text>{\pard \qj Saunavastike:        </xsl:text><xsl:value-of select="saunavastike"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:if test="autotallivastike != '0,00'">
            <xsl:text>{\pard \qj Autotallivastike:        </xsl:text><xsl:value-of select="autotallivastike"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:if test="vesimaksu != '0,00'">           
            <xsl:text>{\pard \qj Vesimaksu:        </xsl:text><xsl:value-of select="vesimaksu"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:if test="saunamaksu != '0,00'">
            <xsl:text>{\pard \qj Saunamaksu:        </xsl:text><xsl:value-of select="saunamaksu"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:if test="autopaikka != '0,00'">
            <xsl:text>{\pard \qj Autopaikkamaksu:    </xsl:text><xsl:value-of select="autopaikka"/><xsl:text>    EUR \par}</xsl:text>
            </xsl:if>
            <xsl:text> \line</xsl:text>
            <xsl:text>{\pard \b Yhteensä: \tab </xsl:text><xsl:value-of select="maksettava"/><xsl:text> EUR /KK \par}\line</xsl:text>
            <xsl:text>{\pard \i Alla seuraavan laskutuskauden maksettavat vastikemaksut, laita rasti ruutuun maksun merkiksi niin voit seurata maksujasi.\par}     \line</xsl:text>
           
            <xsl:for-each select="erapaivat" xml:space="default">
            <xsl:text disable-output-escaping="yes">{\pard Eräpäivä: </xsl:text><xsl:value-of select="erapaiva"/><xsl:text>    Viitenumero: </xsl:text><xsl:value-of select="viite"/><xsl:text>    Määrä: </xsl:text><xsl:value-of select="maksettava"/><xsl:text> EUR</xsl:text><xsl:text>    Maksettu [   ] \par}</xsl:text>
            </xsl:for-each>
            <xsl:text> \page </xsl:text>
        </xsl:for-each>
        <xsl:text>}</xsl:text>
    </xsl:template>

</xsl:stylesheet>

Not so beautiful or efficient but it get's the thing done and that's all this is about.


Uploaded first version in a month just now, implemented lightweight tracking functions. To get count on visits and what posts are read. Nothing major yet, just groundworks to get some usefull data for this feature. Yeah and now, of to school!

*Update*

Now the stats gathering stuff is completely in place, all stats are collected so that no users can be identified from those and no IP addresses are stored. Just views in term of numbers. Maybe some day I'll make a algorithm to store unique hashes of users visiting (in manner that no private data is collected) to identify returning "customers" etc but I'm not that interested in it right now.

*Update 2*

Live preview:


So the JavaEE course is now behind me, I think I succeeded pretty much in every front imaginable. Seems that I shall be getting another fiver to add to my track record :)

  • I learned Struts
  • I learned Hibernate
  • I learned DAO-model
  • Others
    • Extended usage of Interfaces
    • Abstract classes

Of course all in all, this great platform for further enhancing this blog. Now I just have couple of loose threads to tie and I think I'll have pretty solid platform. Then I think it's time for visual goodies + plugin and theme support.


Ha, managed to finally fix that notorious relative url problem with tinyMCE. Here's what I did, instead of using:

<a href="javascript:tinyMCE.execCommand('inserthtml', false, 'LINK AND IMAGE URL');>IMAGE</a>

I used:

<a href="#" onclick="tinyMCE.execCommand('mceInsertContent',false,'LINK AND IMAGE URL');return false">IMAGE</a>

I think it had something to do with inserthtml being standard moz DOM command and mceInsertContent being tinyMCE's own command. For some reason inserthtml did not regard convert_url rules at all.


Had to take news service offline, there seems to be some nasty bug that manifestes it after while, a long while that is. I'll put it online soon as I have fixed that bug.


View older posts