Added a stylesheet to render accounting XML
authorOlivier Cayrol (Logilab) <Olivier.Cayrol@logilab.fr>
Mon, 31 Aug 2009 13:54:09 +0200
changeset 31 c6db30991a0c
parent 24 3727402422b4
child 32 85a1b82d6a72
Added a stylesheet to render accounting XML
data/accounting-entries.xsl
views/accounting.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/accounting-entries.xsl	Mon Aug 31 13:54:09 2009 +0200
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                version="1.0">
+  <xsl:output method="text" encoding="UTF-8"/>
+
+  <xsl:template match="*">
+    <xsl:param name="indent" select="''"/>
+
+    <xsl:call-template name="write-element">
+      <xsl:with-param name="indent" select="$indent"/>
+    </xsl:call-template>
+  </xsl:template>
+
+  <xsl:template match="ecriture">
+    <xsl:param name="indent" select="''"/>
+
+    <xsl:call-template name="write-element">
+      <xsl:with-param name="indent" select="$indent"/>
+    </xsl:call-template>
+    <xsl:if test="following-sibling::ecriture">
+      <xsl:text>
+</xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template match="@*">
+    <xsl:text> </xsl:text>
+    <xsl:value-of select="name()"/>
+    <xsl:text>="</xsl:text>
+    <xsl:value-of select="."/>
+    <xsl:text>"</xsl:text>
+  </xsl:template>
+
+  <xsl:template match="text()">
+    <xsl:if test="normalize-space(.)">
+      <xsl:value-of select="."/>
+    </xsl:if>
+  </xsl:template>
+
+  <xsl:template name="write-element">
+    <xsl:param name="indent" select="''"/>
+
+    <xsl:text>
+</xsl:text>
+    <xsl:value-of select="$indent"/>
+    <xsl:text>&lt;</xsl:text>
+    <xsl:value-of select="name()"/>
+    <xsl:apply-templates select="@*">
+      <xsl:sort select="name()"/>
+    </xsl:apply-templates>
+    <xsl:if test="not(*|text())">
+      <xsl:text>/</xsl:text>
+    </xsl:if>
+    <xsl:text>></xsl:text>
+
+    <xsl:if test="*|text()">
+      <xsl:apply-templates select="*|text()">
+	<xsl:with-param name="indent" select="concat($indent,'  ')"/>
+      </xsl:apply-templates>
+
+      <xsl:if test="*">
+	<xsl:text>
+</xsl:text>
+        <xsl:value-of select="$indent"/>
+      </xsl:if>
+      <xsl:text>&lt;/</xsl:text>
+      <xsl:value-of select="name()"/>
+      <xsl:text>></xsl:text>
+    </xsl:if>
+  </xsl:template>
+
+</xsl:stylesheet>
--- a/views/accounting.py	Fri Aug 14 16:06:12 2009 +0200
+++ b/views/accounting.py	Mon Aug 31 13:54:09 2009 +0200
@@ -38,6 +38,8 @@
         """display a list of entities by calling their <item_vid> view
         """
         self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding)
+        self.w(u'<?xml-stylesheet href="%saccounting-entries.xsl" '
+               u'rel="stylesheet" type="text/xsl"?>\n' % self.req.datadir_url)
         self.w(u'<ecritures>\n')
         for i in xrange(self.rset.rowcount):
             self.cell_call(i, 0)