-
Notifications
You must be signed in to change notification settings - Fork 2
/
cards-poker.xsl
239 lines (221 loc) · 7.85 KB
/
cards-poker.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?xml version="1.0"?>
<!-- vim: set ts=2 sw=2: -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:str="http://exslt.org/strings"
version="1.0">
<xsl:param name="card_width">2.5</xsl:param>
<xsl:param name="card_height">3.5</xsl:param>
<xsl:param name="page_width">2.5</xsl:param>
<xsl:param name="page_height">3.5</xsl:param>
<xsl:param name="columns">1</xsl:param>
<xsl:template match="/cards">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="all-pages">
<xsl:attribute name="page-width"><xsl:value-of select="$page_width"/></xsl:attribute>
<xsl:attribute name="page-height"><xsl:value-of select="$page_height"/></xsl:attribute>
<fo:region-body margin="0in 0in" column-gap="0in"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="my-sequence">
<fo:repeatable-page-master-reference master-reference="all-pages"/>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-sequence">
<fo:flow flow-name="xsl-region-body" font-weight="bold">
<fo:table>
<fo:table-body>
<xsl:for-each select="cardset/whitecard|cardset/blackcard">
<!--<xsl:variable name="i" select="position() + count(../preceding-sibling::cardset/*)"/>-->
<!--<xsl:variable name="c" select="./following-sibling::* | ../following-sibling::cardset/*"/>-->
<!--<xsl:if test="($i mod $columns) = 1">-->
<fo:table-row>
<xsl:apply-templates select="."/>
<!--
<xsl:call-template name="loop">
<xsl:with-param name="col">1</xsl:with-param>
<xsl:with-param name="c"><xsl:value-of select="$c"/></xsl:with-param>
</xsl:call-template>
-->
</fo:table-row>
<!--
</xsl:if>
-->
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template name="loop">
<xsl:param name="col"/>
<xsl:param name="c"/>
<xsl:if test="$col < $columns">
<xsl:if test="count($c[$col]) != 0">
<xsl:apply-templates select="$c[$col]"/>
</xsl:if>
<xsl:call-template name="loop">
<xsl:with-param name="col"><xsl:value-of select="$col + 1"/></xsl:with-param>
<xsl:with-param name="c"><xsl:value-of select="$c"/></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="whitecard">
<fo:table-cell border="1px solid black" padding=".1in" font-family="DejaVu Sans, Arial, sans-serif">
<xsl:attribute name="width">
<xsl:value-of select="$card_width"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<xsl:attribute name="height">
<xsl:value-of select="$card_height - .2"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<xsl:attribute name="font-size">
<xsl:choose>
<xsl:when test="@font-size">
<xsl:value-of select="@font-size"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>14pt</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<fo:block>
<xsl:apply-templates/>
</fo:block>
<fo:block-container absolute-position="absolute">
<xsl:attribute name="top">
<xsl:value-of select="$card_height - .3"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<fo:block>
<fo:external-graphic>
<xsl:attribute name="content-width">
<xsl:value-of select="$card_width - .2"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<xsl:attribute name="src">
<xsl:text>url('footers/</xsl:text>
<xsl:value-of select="../@name"/>
<xsl:text>/footer.svg')</xsl:text>
</xsl:attribute>
</fo:external-graphic>
</fo:block>
</fo:block-container>
</fo:table-cell>
</xsl:template>
<xsl:template match="blackcard">
<fo:table-cell border="1px solid white" padding=".1in" background-color="#231f20" color="white" font-family="DejaVu Sans, Arial, sans-serif">
<xsl:attribute name="width"> <xsl:value-of select="$card_width"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="height"> <xsl:value-of select="$card_height - .2"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="font-size">
<xsl:choose>
<xsl:when test="@font-size">
<xsl:value-of select="@font-size"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>14pt</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<fo:block>
<xsl:apply-templates/>
</fo:block>
<xsl:variable name="pick">
<xsl:choose>
<xsl:when test="./@pick">
<xsl:value-of select="./@pick"/>
</xsl:when>
<xsl:when test="count(.//blank) > 0">
<xsl:value-of select="count(.//blank)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$pick = 1">
<fo:block-container absolute-position="absolute">
<xsl:attribute name="top">
<xsl:value-of select="$card_height - .3"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<fo:block>
<fo:external-graphic>
<xsl:attribute name="content-width"> <xsl:value-of select="$card_width - .2"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="src">
<xsl:text>url('footers/</xsl:text>
<xsl:value-of select="../@name"/>
<xsl:text>/blackfooter.svg')</xsl:text>
</xsl:attribute>
</fo:external-graphic>
</fo:block>
</fo:block-container>
</xsl:when>
<xsl:when test="$pick = 2">
<fo:block-container absolute-position="absolute">
<xsl:attribute name="top">
<xsl:value-of select="$card_height - .3"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<fo:block>
<fo:external-graphic>
<xsl:attribute name="content-width"> <xsl:value-of select="$card_width - .2"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="src">
<xsl:text>url('footers/</xsl:text>
<xsl:value-of select="../@name"/>
<xsl:text>/blackfooterpick2.svg')</xsl:text>
</xsl:attribute>
</fo:external-graphic>
</fo:block>
</fo:block-container>
</xsl:when>
<xsl:when test="$pick = 3">
<fo:block-container absolute-position="absolute">
<xsl:attribute name="top">
<xsl:value-of select="$card_height - .3"/>
<xsl:text>in</xsl:text>
</xsl:attribute>
<fo:block>
<fo:external-graphic>
<xsl:attribute name="content-width"> <xsl:value-of select="$card_width - .2"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="src">
<xsl:text>url('footers/</xsl:text>
<xsl:value-of select="../@name"/>
<xsl:text>/blackfooterpick3.svg')</xsl:text>
</xsl:attribute>
</fo:external-graphic>
</fo:block>
</fo:block-container>
</xsl:when>
<xsl:otherwise>
<xsl:message>Problem!</xsl:message>
</xsl:otherwise>
</xsl:choose>
</fo:table-cell>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="img">
<fo:external-graphic>
<xsl:attribute name="content-width"> <xsl:value-of select="$card_width - .2"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="content-height"> <xsl:value-of select="$card_height - .4"/> <xsl:text>in</xsl:text> </xsl:attribute>
<xsl:attribute name="src">
<xsl:text>url('</xsl:text>
<xsl:value-of select="@src"/>
<xsl:text>')</xsl:text>
</xsl:attribute>
</fo:external-graphic>
</xsl:template>
<xsl:template match="br">
<fo:block/>
</xsl:template>
<xsl:template match="blank">
<fo:inline text-decoration="underline">
<xsl:text>            </xsl:text>
</fo:inline>
</xsl:template>
</xsl:stylesheet>