Fixed some bugs, now uses XSLT + xsl:output instead unfortunately, but works. Added some tests too.