-
Notifications
You must be signed in to change notification settings - Fork 0
/
flashcards-5x2-layout-fo.xsl
215 lines (186 loc) · 8.31 KB
/
flashcards-5x2-layout-fo.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?xml version="1.0" encoding="utf-8"?>
<!-- ============================================================= -->
<!-- XSL-FO for accounts worksheets
============================================================= -->
<xsl:stylesheet version="2.0" xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- By default, prints fronts and backs. Set $pages='recto' (or 'verso')
for fronts only (or backs) -->
<xsl:param name="pages">all</xsl:param>
<xsl:attribute-set name="trace">
<!--<xsl:attribute name="border">thin solid blue</xsl:attribute>-->
</xsl:attribute-set>
<xsl:attribute-set name="cell">
<xsl:attribute name="padding">6pt</xsl:attribute>
<xsl:attribute name="font-family">Calibri</xsl:attribute>
<xsl:attribute name="width">3.5in</xsl:attribute>
<xsl:attribute name="height">130pt</xsl:attribute>
<xsl:attribute name="border-width">1pt</xsl:attribute>
<xsl:attribute name="border-color">gray</xsl:attribute>
<xsl:attribute name="border-style">dotted</xsl:attribute>
<xsl:attribute name="overflow">hidden</xsl:attribute>
<xsl:attribute name="padding-right">8pt</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="11in"
page-width="8.5in"
margin-top="0.5in" margin-bottom="0.5in"
margin-left="0.75in" margin-right="0.75in">
<fo:region-body region-name="content" margin-top="0in"
margin-bottom="0in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates/>
</fo:root>
</xsl:template>
<xsl:template match="/pages">
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="content">
<xsl:apply-templates select="page">
<!-- reverses pages on the verso <xsl:sort select="position() * (if ($pages eq 'verso') then -1 else 1)"/>-->
</xsl:apply-templates> </fo:flow>
</fo:page-sequence>
</xsl:template>
<xsl:key name="page-faces-except" match="page/*"
use="distinct-values(../*/local-name())[not(. eq current()/local-name())]"/>
<!-- 'all' fails to match anything, so all come through -->
<xsl:template match="key('page-faces-except',$pages)"/>
<xsl:template match="recto | verso">
<fo:table font-size="10pt" width="7in" keep-together.within-page="10"><!-- 7.5in wide -->
<fo:table-column column-number="1" column-width="3.5in"/>
<fo:table-column column-number="2" column-width="3.5in"/>
<fo:table-body>
<xsl:apply-templates/>
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="row">
<fo:table-row>
<xsl:apply-templates/>
<xsl:if test="empty(*)">
<fo:table-cell xsl:use-attribute-sets="cell">
<xsl:apply-templates select="parent::*" mode="credit-block"/>
</fo:table-cell>
<fo:table-cell xsl:use-attribute-sets="cell">
<xsl:apply-templates select="parent::*" mode="credit-block"/>
</fo:table-cell>
</xsl:if>
</fo:table-row>
</xsl:template>
<xsl:template match="recto" mode="credit-block">
<fo:block-container display-align="center" text-align="center">
<fo:block font-size="90%" font-weight="bold">Dickinson College Core Ancient Greek Vocabulary Set</fo:block>
<fo:block>http://dcc.dickinson.edu/greek-core-list</fo:block>
<fo:block>524 of the commonest words in Ancient Greek</fo:block>
<fo:block>Borrowed with thanks in the spirit of share-alike</fo:block>
<fo:block space-before="2pt">
<!--file:/C:/Users/Wendell/Documents/GitHub/GreekVocab/-->
<fo:external-graphic content-width="0.8in" content-height="scale-to-fit"
src="url('qr-dcc-dickinson-e.svg')"/>
</fo:block>
</fo:block-container>
</xsl:template>
<xsl:template match="verso" mode="credit-block">
<fo:block-container display-align="center" text-align="center">
<fo:block margin-top="6pt">Set onto 3½" × 2" cards with XML, XSLT and XSL-FO</fo:block>
<fo:block>http://github.com/wendellpiez/GreekVocab</fo:block>
<fo:block space-before="2pt">
<!--file:/C:/Users/Wendell/Documents/GitHub/GreekVocab/-->
<fo:external-graphic content-width="0.8in" content-height="scale-to-fit"
src="url('qr-github-com.svg')"/>
</fo:block>
<!--<fo:block text-align="center" margin-top="6pt" font-size="80%">When printing on both sides of (8½" × 11") perforated card stock sheets: flip vertically, on the <fo:inline font-style="italic">short</fo:inline> edge</fo:block>-->
</fo:block-container>
</xsl:template>
<xsl:template match="front"><!-- 130pt total -->
<fo:table-cell xsl:use-attribute-sets="cell">
<xsl:for-each select="dsp">
<xsl:variable name="head">
<xsl:call-template name="headword"/>
</xsl:variable>
<xsl:variable name="rest" select="substring-after(.,$head)"/>
<fo:block-container height="42pt" overflow="hidden" xsl:use-attribute-sets="trace">
<fo:block font-size="24pt">
<xsl:value-of select="translate($head,',','')"/>
</fo:block></fo:block-container>
<fo:block-container height="60pt" overflow="hidden" xsl:use-attribute-sets="trace">
<fo:block font-size="16pt" line-height="20pt">
<xsl:value-of select="$rest"/><xsl:text> </xsl:text>
</fo:block>
</fo:block-container>
</xsl:for-each>
<xsl:call-template name="footer-line"/>
</fo:table-cell>
</xsl:template>
<xsl:template name="footer-line">
<fo:block-container height="20pt" display-align="after" xsl:use-attribute-sets="trace">
<fo:table width="100%" font-size="11pt">
<fo:table-column column-number="1" column-width="20%"/>
<fo:table-column column-number="2" column-width="80%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block font-weight="bold">
<xsl:value-of select="frq"/>
<xsl:text> </xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align="end" font-style="italic">
<xsl:value-of select="poS"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block-container>
</xsl:template>
<xsl:template match="back">
<fo:table-cell xsl:use-attribute-sets="cell">
<xsl:variable name="whose" select="."/>
<xsl:for-each select="dsp">
<xsl:variable name="head">
<xsl:call-template name="headword"/>
</xsl:variable>
<xsl:variable name="rest" select="substring-after(.,$head)"/>
<fo:block-container height="24pt" overflow="hidden" xsl:use-attribute-sets="trace">
<fo:block font-size="20pt" keep-together.within-line="24" text-align-last="justify">
<xsl:value-of select="translate($head,',','')"/>
<fo:leader leader-pattern="space"/>
<fo:inline font-size="10pt" vertical-align="text-top">
<xsl:value-of select="$whose/cat"/>
</fo:inline>
</fo:block></fo:block-container>
<fo:block-container height="34pt" overflow="hidden" xsl:use-attribute-sets="trace">
<fo:block font-size="13pt" line-height="16pt">
<xsl:value-of select="$rest"/><xsl:text> </xsl:text>
</fo:block></fo:block-container>
</xsl:for-each>
<xsl:for-each select="def">
<fo:block-container height="42pt" overflow="hidden" xsl:use-attribute-sets="trace">
<fo:block font-size="10pt" line-height="14pt">
<xsl:apply-templates/>
</fo:block></fo:block-container>
</xsl:for-each>
<xsl:call-template name="footer-line"/>
</fo:table-cell>
</xsl:template>
<!--<xsl:template match="front/* | back/*">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</xsl:template>-->
<xsl:template name="headword">
<xsl:choose>
<xsl:when test="contains(., ' ')">
<xsl:value-of select="substring-before(., ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="string(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>