root/todo/trunk/contrib/todo2pdf.xslt

Revision 290, 2.9 kB (checked in by athomas, 4 years ago)

Initial import.

Line 
1 <?xml version="1.0"?>
2
3 <!--
4
5         After being disappointed in the printed output from a color xterm
6         screenshot, I generated an XSLT/FOP stylesheet that dumps out color
7         pdf, suitable for printing. I include the wrapper (for running it on
8         a debian unstable system - note that I haven't found anywhere to get
9         the w3c.jar other than the upstream FOP sources, nor anywhere else to
10         find org/w3c/dom/svg/SVGFitToViewBox...) and the stylesheet here, for
11         your enjoyment; do whatever you'd like with them. (In practice they
12         need more tuning of the colors, and I left out margin settings
13         altogether.)
14
15         _Mark_ <eichin@thok.org>
16         The Herd Of Kittens
17
18 -->
19
20 <xsl:stylesheet xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21         xmlns:xlink="http://www.w3.org/2000/xlink/namespace/"
22         xmlns:fo="http://www.w3.org/1999/XSL/Format">
23
24         <xsl:output xsl:method="xml" xsl:indent="yes"/>
25         <xsl:strip-space xsl:elements="item bulletlist"/>
26         <xsl:preserve-space xsl:elements="preformatted"/>
27
28         <!-- body -->
29         <xsl:template xsl:match="/">
30                 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
31                         <fo:layout-master-set>
32                                 <fo:simple-page-master
33                                         master-name="todoPage"
34                                         page-height="11in"
35                                         page-width="8.5in">
36                                         <fo:region-body/>
37                                 </fo:simple-page-master>
38                         </fo:layout-master-set>
39                         <fo:page-sequence fo:master-name="todoPage">
40                                 <fo:flow fo:flow-name="xsl-region-body">
41                                         <fo:list-block>
42                                                 <xsl:call-template xsl:name="noteList"/>
43                                         </fo:list-block>
44                                 </fo:flow>
45                         </fo:page-sequence>
46                 </fo:root>
47         </xsl:template>
48
49         <xsl:template xsl:name="noteList">
50                 <xsl:for-each xsl:select="todo/note">
51                         <xsl:call-template xsl:name="noteItem"/>
52                 </xsl:for-each>
53         </xsl:template>
54
55         <xsl:template xsl:name="noteItem">
56                 <xsl:if xsl:test="not(@done)">
57                         <fo:list-item>
58                                 <fo:list-item-label>
59                                         <fo:block>
60                                                 <xsl:value-of xsl:select="position()" />
61                                         </fo:block>
62                                 </fo:list-item-label>
63                                 <fo:list-item-body>
64                                         <xsl:apply-templates xsl:select="."/>
65                                 </fo:list-item-body>
66                         </fo:list-item>
67                 </xsl:if>
68         </xsl:template>
69
70         <xsl:template xsl:match="note">
71                 <xsl:call-template xsl:name="baseNote"/>
72                 <fo:list-block>
73                         <xsl:for-each xsl:select="./note">
74                                 <xsl:call-template xsl:name="noteItem"/>
75                         </xsl:for-each>
76                 </fo:list-block>
77         </xsl:template>
78
79         <xsl:template xsl:name="baseNote">
80                 <xsl:variable xsl:name="priorityColor">
81                         <xsl:choose>
82                                 <xsl:when xsl:test="@priority = 'veryhigh'">red</xsl:when>
83                                 <xsl:when xsl:test="@priority = 'high'">yellow</xsl:when>
84                                 <xsl:when xsl:test="@priority = 'medium'">orange</xsl:when>
85                                 <xsl:when xsl:test="@priority = 'low'">#000090</xsl:when>
86                                 <xsl:when xsl:test="@priority = 'verylow'">blue</xsl:when>
87                                 <xsl:otherwise>black</xsl:otherwise>
88                         </xsl:choose>
89                 </xsl:variable>
90                 <fo:block fo:color="{$priorityColor}">
91                         <xsl:value-of xsl:select="child::text()[position()=1]"/>
92                 </fo:block>
93         </xsl:template>
94
95 </xsl:stylesheet>
Note: See TracBrowser for help on using the browser.