fo: initial version of ledger.xsl
[ledger-xsl.git] / fo / ledger.xsl
1 <xsl:stylesheet version="1.0"
2                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:fo="http://www.w3.org/1999/XSL/Format">
4
5 <xsl:output indent="yes"/>
6 <xsl:strip-space elements="*"/>
7
8 <xsl:param name="paper.type">A4</xsl:param>
9 <xsl:param name="page.orientation">portrait</xsl:param>
10
11 <xsl:param name="page.margin.bottom">0.5in</xsl:param>
12 <xsl:param name="page.margin.top">0.5in</xsl:param>
13 <xsl:param name="page.margin.inner">1in</xsl:param>
14 <xsl:param name="page.margin.outer">1in</xsl:param>
15
16 <xsl:param name="body.margin.bottom">10mm</xsl:param>
17 <xsl:param name="body.margin.top">10mm</xsl:param>
18 <xsl:param name="body.margin.inner">10mm</xsl:param>
19 <xsl:param name="body.margin.outer">10mm</xsl:param>
20
21 <xsl:param name="page.height.portrait">
22   <xsl:choose>
23     <xsl:when test="$paper.type = 'A4landscape'">210mm</xsl:when>
24     <xsl:when test="$paper.type = 'USletter'">11in</xsl:when>
25     <xsl:when test="$paper.type = 'USlandscape'">8.5in</xsl:when>
26     <xsl:when test="$paper.type = 'A3'">420mm</xsl:when>
27     <xsl:when test="$paper.type = 'A4'">297mm</xsl:when>
28     <xsl:when test="$paper.type = 'A5'">210mm</xsl:when>
29     <xsl:otherwise>11in</xsl:otherwise>
30   </xsl:choose>
31 </xsl:param>
32 <xsl:param name="page.width.portrait">
33   <xsl:choose>
34     <xsl:when test="$paper.type = 'A4landscape'">297mm</xsl:when>
35     <xsl:when test="$paper.type = 'USletter'">8.5in</xsl:when>
36     <xsl:when test="$paper.type = 'USlandscape'">11in</xsl:when>
37     <xsl:when test="$paper.type = 'A3'">297mm</xsl:when>
38     <xsl:when test="$paper.type = 'A4'">210mm</xsl:when>
39     <xsl:when test="$paper.type = 'A5'">148mm</xsl:when>
40     <xsl:otherwise>8.5in</xsl:otherwise>
41   </xsl:choose>
42 </xsl:param>
43
44 <xsl:param name="page.height">
45   <xsl:choose>
46     <xsl:when test="$page.orientation = 'portrait'">
47       <xsl:value-of select="$page.height.portrait"/>
48     </xsl:when>
49     <xsl:otherwise>
50       <xsl:value-of select="$page.width.portrait"/>
51     </xsl:otherwise>
52   </xsl:choose>
53 </xsl:param>
54 <xsl:param name="page.width">
55   <xsl:choose>
56     <xsl:when test="$page.orientation = 'portrait'">
57       <xsl:value-of select="$page.width.portrait"/>
58     </xsl:when>
59     <xsl:otherwise>
60       <xsl:value-of select="$page.height.portrait"/>
61     </xsl:otherwise>
62   </xsl:choose>
63 </xsl:param>
64
65 <xsl:template match="/">
66   <fo:root>
67     <fo:layout-master-set>
68       <fo:simple-page-master master-name="first-page"
69                              page-width="{$page.width}"
70                              page-height="{$page.height}"
71                              margin-top="{$page.margin.top}"
72                              margin-bottom="{$page.margin.bottom}"
73                              margin-left="{$page.margin.inner}"
74                              margin-right="{$page.margin.outer}">
75         <fo:region-body margin-bottom="{$body.margin.bottom}"
76                         margin-top="{$body.margin.top}"/>
77       </fo:simple-page-master>
78     </fo:layout-master-set>
79
80     <fo:page-sequence master-reference="first-page">
81       <fo:flow flow-name="xsl-region-body">
82         <fo:block
83             font-family="sans-serif"
84             font-size="24pt"
85             text-align="center">
86           Ledger Report
87         </fo:block>
88         <xsl:apply-templates/>
89       </fo:flow>
90     </fo:page-sequence>
91   </fo:root>
92 </xsl:template>
93
94 <xsl:template match="text()" />
95
96 <xsl:template match="accounts">
97   <fo:block>
98     <fo:block
99         font-family="sans-serif"
100         font-size="18pt">
101       Balance Report
102     </fo:block>
103     <xsl:apply-templates/>
104   </fo:block>
105 </xsl:template>
106
107 <xsl:template match="accounts/account">
108   <fo:block border-width="0.5mm" border-style="solid" border-color="green">
109     <xsl:apply-templates/>
110   </fo:block>
111 </xsl:template>
112
113 <xsl:template match="accounts/*/account">
114   <xsl:choose>
115     <xsl:when test="./fullname = ./name">
116       <fo:block keep-together="always" border-width="0.5mm"
117                 border-style="solid" border-color="red">
118         <xsl:apply-templates/>
119       </fo:block>
120     </xsl:when>
121     <xsl:otherwise>
122       <fo:block border-width="0.2mm"
123                 border-style="solid" border-color="black">
124         <xsl:apply-templates/>
125       </fo:block>
126     </xsl:otherwise>
127   </xsl:choose>
128 </xsl:template>
129
130 <xsl:template match="account/account-total">
131   <fo:block>
132     <xsl:value-of select="../fullname"/>
133   </fo:block>
134   <fo:table table-layout="fixed" width="100%">
135     <fo:table-body>
136       <xsl:apply-templates/>
137     </fo:table-body>
138   </fo:table>
139 </xsl:template>
140
141 <xsl:template match="account/account-total/balance/amount|account/account-total/amount">
142   <fo:table-row>
143     <fo:table-cell>
144       <fo:block font-family="monospace" text-align="right">
145         <xsl:value-of select="./commodity/symbol"/>
146       </fo:block>
147     </fo:table-cell>
148     <fo:table-cell>
149       <fo:block font-family="monospace" text-align="right">
150         <xsl:value-of select="format-number(./quantity, '###0.00')"/>
151       </fo:block>
152     </fo:table-cell>
153   </fo:table-row>
154 </xsl:template>
155
156 <xsl:template match="transactions">
157   <fo:block>
158     <fo:block
159         page-break-before="always"
160         font-family="sans-serif"
161         font-size="18pt">
162       Register Report
163     </fo:block>
164     <xsl:apply-templates/>
165   </fo:block>
166 </xsl:template>
167
168 <xsl:template match="transaction">
169   <fo:block-container  keep-together="always" border-width="0.2mm"
170                        border-style="solid">
171     <xsl:apply-templates/>
172   </fo:block-container>
173 </xsl:template>
174
175 <xsl:template match="transaction/date">
176   <fo:block-container>
177     <fo:block>
178       <xsl:value-of select="concat(substring(., 1, 4),'-',substring(., 6, 2),'-',substring(., 9, 2))"/>
179     </fo:block>
180   </fo:block-container>
181 </xsl:template>
182
183 <xsl:template match="transaction/payee">
184   <fo:block-container background-color="silver">
185     <fo:block>
186       <xsl:value-of select="."/>
187     </fo:block>
188   </fo:block-container>
189 </xsl:template>
190
191 <xsl:template match="postings">
192   <fo:block-container space-after="3mm">
193     <fo:table table-layout="fixed" width="100%">
194       <fo:table-body>
195         <xsl:apply-templates/>
196       </fo:table-body>
197     </fo:table>
198   </fo:block-container>
199 </xsl:template>
200
201 <xsl:template match="postings/posting">
202   <fo:table-row>
203     <xsl:apply-templates/>
204   </fo:table-row>
205 </xsl:template>
206
207 <xsl:template match="postings/posting/account/name">
208   <fo:table-cell>
209     <fo:block font-family="monospace">
210       <xsl:value-of select="."/>
211     </fo:block>
212   </fo:table-cell>
213 </xsl:template>
214
215 <xsl:template match="postings/posting/post-amount/amount/quantity">
216   <fo:table-cell>
217     <fo:block font-family="monospace" text-align="right">
218       <xsl:value-of select="format-number(., '####.00')"/>
219     </fo:block>
220   </fo:table-cell>
221 </xsl:template>
222
223 <xsl:template match="postings/posting/post-amount/amount/commodity/symbol">
224   <fo:table-cell>
225     <fo:block font-family="monospace" text-align="right">
226       <xsl:value-of select="."/>
227     </fo:block>
228   </fo:table-cell>
229 </xsl:template>
230 </xsl:stylesheet>