Comments.
[thenextsample.git] / pottery2docbook.xsl
blob6ba0cd62040802c8e6f65f688125d4d0ead73c1e
1 <?xml version='1.0' encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0"
3 xml:lang="en"
4 xmlns="http://docbook.org/ns/docbook"
5 xmlns:db="http://docbook.org/ns/docbook"
6 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 xmlns:xlink="http://www.w3.org/1999/xlink"
8 xmlns:ex="http://exslt.org/dates-and-times"
9 xmlns:em="http://exslt.org/math"
10 xmlns:es="http://exslt.org/sets"
11 xmlns:ec="http://exslt.org/common"
12 xmlns:esets="http://exslt.org/sets"
13 xmlns:p="tag:fenglich.fastmail.fm,2007:Pottery">
16 <!-- Do some business logic validation. -->
17 <xsl:template match="/">
18 <!-- glazing referencing brushons. -->
19 <xsl:variable name="invalidGlazeRef">
20 <xsl:for-each select="//p:glazing">
21 <xsl:variable name="name" select="@idref"/>
22 <xsl:value-of select="//p:glaze[@xml:id = $name and @type = 'BrushOn']/@xml:id"/>
23 </xsl:for-each>
24 </xsl:variable>
26 <xsl:if test="string-length(normalize-space($invalidGlazeRef)) > 0">
27 <xsl:message terminate="yes"><xsl:value-of select="$invalidGlazeRef"/> is referenced as a non-brushon, while it in fact is.</xsl:message>
28 </xsl:if>
30 <!-- brushons referencing non-brushons. -->
31 <xsl:variable name="invalidBrushOnGlazeRef">
32 <xsl:for-each select="//p:brushon">
33 <xsl:variable name="name" select="@idref"/>
34 <xsl:value-of select="//p:glaze[@xml:id = $name and @type != 'BrushOn']/@xml:id"/>
35 </xsl:for-each>
36 </xsl:variable>
38 <xsl:if test="string-length(normalize-space($invalidBrushOnGlazeRef)) > 0">
39 <xsl:message terminate="yes"><xsl:value-of select="$invalidBrushOnGlazeRef"/> are referenced as a brushon, while it isn't.</xsl:message>
40 </xsl:if>
42 <xsl:apply-templates/>
43 </xsl:template>
45 <xsl:template match="p:pottery">
46 <book xml:lang="en">
47 <info>
48 <title>The Next Sample</title>
49 <author>
50 <personname>
51 <firstname>Frans</firstname>
52 <surname>Englich</surname>
53 </personname>
54 <email>fenglich@fastmail.fm</email>
55 <address>
56 <phone>+46-702-411091</phone>
57 </address>
58 </author>
59 <pubdate><xsl:value-of select="ex:date()"/></pubdate>
60 <legalnotice>
61 <para>Copyright (c) 2007-2008 Frans Englich</para>
62 <para>Permission is granted to copy, distribute and/or modify this document
63 under the terms of the GNU Free Documentation License, Version 1.2
64 or any later version published by the Free Software Foundation;
65 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
66 Texts. A copy of the license can be obtained at the <phrase xlink:href="http://www.gnu.org/licenses/fdl.html">Free Software Foundation's website</phrase> or by contacting the author.</para>
67 </legalnotice>
68 </info>
70 <xsl:apply-templates select="p:pieces"/>
71 <xsl:apply-templates select="p:glazes"/>
73 <chapter xml:id="NonGlazeSamples">
74 <title>Non-glaze Samples</title>
75 <para>This section contains samples which aren't of glazes,
76 such as melt tests. See also the samples that have at least
77 <phrase xlink:href="#Transparent">transparent
78 glaze</phrase> as glazing, which contains similar kind
79 of samples.</para>
81 <xsl:apply-templates select="p:samples/p:sample[not(p:glazing | p:brushon)]"/>
82 </chapter>
84 <chapter xml:id="OvenPrograms">
85 <title>Oven Programs</title>
87 <para>Unless otherwise stated, all firings were done with the following settings.</para>
88 <informaltable>
89 <tgroup cols="8">
90 <thead>
91 <row>
92 <entry>Program Code</entry>
93 <entry>Type</entry>
94 <entry>C/h 1</entry>
95 <entry>Temp 1</entry>
96 <entry>Time 1</entry>
97 <entry>C/h 2</entry>
98 <entry>Temp 2</entry>
99 <entry>Time 2</entry>
100 <entry>C/h 3</entry>
101 </row>
102 </thead>
103 <tbody>
104 <row>
105 <entry>P1</entry>
106 <entry>Bisque</entry>
107 <entry>80</entry>
108 <entry>80</entry>
109 <entry>300</entry>
110 <entry>150</entry>
111 <entry>960</entry>
112 <entry>30</entry>
113 <entry>700</entry>
114 </row>
115 <row>
116 <entry>P2</entry>
117 <entry>Decal &amp; Luster</entry>
118 <entry>150</entry>
119 <entry>650</entry>
120 <entry>0</entry>
121 <entry>200</entry>
122 <entry>780</entry>
123 <entry>0</entry>
124 <entry>700</entry>
125 </row>
126 <row>
127 <entry>P3</entry>
128 <entry>Unused Bisque Program</entry>
129 <entry>80</entry>
130 <entry>80</entry>
131 <entry>540</entry>
132 <entry>150</entry>
133 <entry>960</entry>
134 <entry>0</entry>
135 <entry>500</entry>
136 </row>
137 <row>
138 <entry>P4</entry>
139 <entry>Glaze</entry>
140 <entry>150</entry>
141 <entry>600</entry>
142 <entry>0</entry>
143 <entry>200</entry>
144 <entry>1240</entry>
145 <entry>10</entry>
146 <entry>500</entry>
147 </row>
148 </tbody>
149 </tgroup>
150 </informaltable>
152 </chapter>
154 <xsl:apply-templates select="p:clays"/>
156 <xsl:call-template name="sourcesAppendix"/>
157 </book>
158 </xsl:template>
160 <xsl:template match="p:pieces">
161 <chapter xml:id="Pieces">
162 <title>Pieces</title>
164 <para>A total of <xsl:value-of select="count(p:piece)"/> pieces.</para>
166 <para>The IDs assigned to pieces are arbitrary and not sequential. They don't reflect cronologically
167 the creation. However, they are sorted numerically in this document for quick lookup.</para>
169 <xsl:apply-templates select="p:piece">
170 <xsl:sort data-type="number" select="number(substring(@xml:id, 2))"/>
171 </xsl:apply-templates>
172 </chapter>
173 </xsl:template>
175 <xsl:template match="p:piece">
176 <section>
177 <xsl:attribute name="xml:id"><xsl:value-of select="@xml:id"/></xsl:attribute>
178 <xsl:attribute name="xreflabel"><xsl:value-of select="@xml:id"/></xsl:attribute>
179 <title>
180 <xsl:value-of select="substring(@xml:id, 2)"/>
181 </title>
182 <xsl:apply-templates/>
183 <xsl:call-template name="createReferences"/>
184 </section>
185 </xsl:template>
187 <xsl:template match="p:clayref">
188 <para>
189 <emphasis>Clay</emphasis>: <phrase xlink:href="#{@idref}">
190 <xsl:value-of select="/p:pottery/p:clays/p:clay[@xml:id = current()/@idref]/@name"/></phrase>
191 <xsl:apply-templates select="@weightWhenWet"/>
192 </para>
194 </xsl:template>
196 <xsl:template match="@weightWhenWet">
197 <xsl:text>, weight </xsl:text>
198 <emphasis>when wet</emphasis>:
199 <constant><xsl:value-of select="."/></constant> g
200 </xsl:template>
202 <xsl:template match="p:note">
203 <formalpara>
204 <title><xsl:value-of select="@date"/></title>
205 <para><xsl:value-of select="."/></para>
206 </formalpara>
207 </xsl:template>
209 <xsl:template match="p:glazes">
210 <chapter xml:id="Glazes">
211 <title>Glazes by Color</title>
213 <para>A total of <xsl:value-of select="count(//p:sample)"/> sample tiles.</para>
215 <xsl:for-each select="esets:distinct(p:glaze/@category)">
216 <xsl:sort select="."/>
218 <section>
219 <xsl:attribute name="xml:id"><xsl:value-of select="."/></xsl:attribute>
220 <title><xsl:value-of select="."/></title>
221 <xsl:apply-templates select="(/)//p:glaze[@category = current()]">
222 <xsl:sort select="@name"/>
223 </xsl:apply-templates>
224 </section>
225 </xsl:for-each>
226 </chapter>
227 </xsl:template>
229 <xsl:template match="p:glaze">
230 <section>
231 <xsl:attribute name="xml:id"><xsl:value-of select="@xml:id"/></xsl:attribute>
232 <xsl:attribute name="xreflabel"><xsl:value-of select="@name"/></xsl:attribute>
233 <title>
234 <xsl:value-of select="@name"/>
235 <xsl:if test="@productID">,
236 <xsl:value-of select="@productID"/>
237 </xsl:if>
238 <xsl:if test="@type = 'BrushOn'"> (brush-on)</xsl:if>
239 </title>
241 <xsl:apply-templates select="@manufacturer"/>
242 <xsl:apply-templates select="db:para"/>
244 <xsl:apply-templates select="p:recipe"/>
246 <xsl:call-template name="createReferences"/>
248 <xsl:variable name="piecesUsing" select="//p:pieces/p:piece[p:glazing/@idref = current()/@xml:id]/@xml:id"/>
249 <xsl:if test="$piecesUsing">
250 <db:para>Used on
251 <xsl:choose>
252 <xsl:when test="count($piecesUsing) > 1">pieces</xsl:when>
253 <xsl:otherwise>piece</xsl:otherwise>
254 </xsl:choose>
256 <xsl:text> </xsl:text>
258 <xsl:call-template name="listItems">
259 <xsl:with-param name="items" select="$piecesUsing"/>
260 </xsl:call-template>
261 </db:para>
262 </xsl:if>
264 <db:para/>
265 <xsl:variable name="secondaryTiles" select="//p:samples/p:sample[(p:brushon | p:glazing)[position() > 1][@idref = current()/@xml:id]]/@xml:id"/>
267 <xsl:if test="$secondaryTiles">
268 <para>Appears as a secondary glaze on
269 <xsl:choose>
270 <xsl:when test="count($piecesUsing) > 1">tiles</xsl:when>
271 <xsl:otherwise>tile</xsl:otherwise>
272 </xsl:choose>
274 <xsl:text> </xsl:text>
276 <xsl:call-template name="listItems">
277 <xsl:with-param name="items" select="$secondaryTiles"/>
278 </xsl:call-template>
279 </para>
280 </xsl:if>
282 <xsl:variable name="tiles" select="//p:samples/p:sample[(p:brushon | p:glazing)[1][@idref = current()/@xml:id]]"/>
283 <xsl:apply-templates select="$tiles">
284 <!-- TODO This just doesn't seem to work. -->
285 <xsl:sort data-type="number" select="number(substring(@xml:id, 2))"/>
286 <!--<xsl:sort data-type="number" select="number(p:glazing/@hydrometerGravity)"/>-->
287 <xsl:with-param name="mainGlaze" select="@xml:id"/>
288 </xsl:apply-templates>
289 </section>
290 </xsl:template>
292 <xsl:template match="p:glaze/@manufacturer">
293 <db:para>From: <xsl:value-of select="."/>.</db:para>
294 </xsl:template>
296 <xsl:template name="listItems">
297 <xsl:param name="items"/>
299 <xsl:for-each select="$items">
300 <xsl:sort select="."/>
301 <db:xref xlink:href="#{.}"/>
302 <xsl:if test="position() = last() - 1">
303 <xsl:text> and </xsl:text>
304 </xsl:if>
305 <xsl:if test="position() &lt; last() - 1">
306 <xsl:text>, </xsl:text>
307 </xsl:if>
308 <xsl:if test="position() = last()">
309 <xsl:text>.</xsl:text>
310 </xsl:if>
311 </xsl:for-each>
312 </xsl:template>
314 <xsl:template name="imageForSample">
315 <xsl:param name="sampleName"/>
316 <xsl:param name="imageName"/>
317 <mediaobject>
318 <imageobject>
319 <imagedata align="right" format="JPG" fileref="../Images/Samples/{$sampleName}/{$imageName}.jpg"/>
320 </imageobject>
321 </mediaobject>
322 </xsl:template>
324 <xsl:template match="p:piece/p:image">
325 <mediaobject>
326 <imageobject>
327 <imagedata align="right" format="JPG" fileref="../Images/Pieces/{../@xml:id}/{.}.jpg"/>
328 </imageobject>
329 </mediaobject>
330 </xsl:template>
332 <xsl:template match="p:sample">
333 <xsl:param name="mainGlaze"/>
334 <section>
335 <xsl:attribute name="xml:id"><xsl:value-of select="@xml:id"/></xsl:attribute>
336 <xsl:attribute name="xreflabel"><xsl:value-of select="@xml:id"/></xsl:attribute>
337 <title><xsl:value-of select="@xml:id"/></title>
339 <para><date><xsl:value-of select="@date"/></date></para>
340 <para>
341 <xsl:apply-templates select="(p:glazing | p:brushon)[@idref = $mainGlaze]" mode="lowKeyGlazing"/>
342 </para>
343 <xsl:variable name="additionalGlazes" select="(p:brushon | p:glazing)[@idref != $mainGlaze]"/>
344 <xsl:if test="(p:brushon | p:glazing)[@idref != $mainGlaze]">
345 <para>Additional glaze<xsl:if test="count($additionalGlazes) > 1">s</xsl:if>:</para>
346 <xsl:apply-templates select="(p:brushon | p:glazing)[@idref != $mainGlaze]"/>
347 </xsl:if>
348 <xsl:apply-templates select="p:clayref"/>
350 <xsl:call-template name="createReferences"/>
352 <xsl:apply-templates select="db:para"/>
353 <xsl:apply-templates mode="doImage" select="."/>
354 </section>
355 </xsl:template>
357 <xsl:template name="createReferences">
358 <xsl:variable name="id" select="@xml:id"/>
359 <xsl:variable name="referencedFrom" select="(/)//@xml:id[parent::node()//@xlink:href[substring-after(., '#') = $id]]"/>
361 <xsl:if test="$referencedFrom">
362 <para>
363 <xsl:text>Referenced by: </xsl:text>
364 <xsl:call-template name="listItems">
365 <xsl:with-param name="items" select="$referencedFrom"/>
366 </xsl:call-template>
367 </para>
368 </xsl:if>
369 </xsl:template>
371 <xsl:template mode="doImage" match="p:sample">
372 <xsl:call-template name="imageForSample">
373 <xsl:with-param name="sampleName" select="@xml:id"/>
374 <xsl:with-param name="imageName" select="@xml:id"/>
375 </xsl:call-template>
376 </xsl:template>
378 <xsl:template match="p:sample/p:para">
379 <formalpara>
380 <title><xsl:value-of select="../@date"/></title>
381 <xsl:copy>
382 <xsl:apply-templates select="."/>
383 </xsl:copy>
384 </formalpara>
385 </xsl:template>
387 <xsl:template match="p:glazing">
388 <para><phrase xlink:href="#{@idref}"><xsl:value-of select="/p:pottery/p:glazes/p:glaze[@xml:id = current()/@idref]/@name"/></phrase>,
389 <xsl:apply-templates select="." mode="lowKeyGlazing"/>
390 </para>
391 </xsl:template>
393 <xsl:template match="p:brushon">
394 <para><phrase xlink:href="#{@idref}"><xsl:value-of select="/p:pottery/p:glazes/p:glaze[@xml:id = current()/@idref]/@name"/></phrase></para>
395 </xsl:template>
397 <xsl:template match="p:glazing" mode="lowKeyGlazing">
398 <xsl:choose>
399 <xsl:when test="@hydrometerGravity">
400 <xsl:apply-templates select="@hydrometerGravity"/>
401 </xsl:when>
402 <xsl:otherwise>
403 <emphasis>hydrometer gravity unknown</emphasis>,
404 </xsl:otherwise>
405 </xsl:choose>
406 <xsl:apply-templates select="@sieved"/>
407 </xsl:template>
409 <xsl:template match="@hydrometerGravity">
410 <emphasis>hydrometer gravity</emphasis>
411 <xsl:text> </xsl:text>
412 <constant><xsl:value-of select="."/></constant>,
413 </xsl:template>
415 <xsl:template match="@sieved">
416 <emphasis>
417 <xsl:choose>
418 <xsl:when test=". = 'WithMixer'">
419 with mixer
420 </xsl:when>
421 <xsl:when test=". = 'no'">
422 not sieved
423 </xsl:when>
424 <xsl:otherwise>
425 sieved with mesh size <constant><xsl:value-of select="."/></constant>
426 </xsl:otherwise>
427 </xsl:choose>
428 </emphasis>
429 </xsl:template>
431 <xsl:template name="sourcesAppendix">
432 <appendix xml:id="SourceFiles">
433 <title>Sources</title>
434 <para>This document was generated from the following sources. The string following the file date is the git SHA1 checksum.</para>
435 <itemizedlist>
436 <xsl:apply-templates select="document('sources.xml')/p:sources/p:source"/>
437 </itemizedlist>
438 </appendix>
439 </xsl:template>
441 <xsl:template match="p:source">
442 <listitem>
443 <para>
444 <filename><xsl:value-of select="@href"/></filename>
445 <xsl:text>, </xsl:text>
446 <date><xsl:value-of select="@date"/></date>
447 <xsl:text>, </xsl:text>
448 <systemitem><xsl:value-of select="@gitSHA1"/></systemitem>
449 </para>
450 </listitem>
451 </xsl:template>
453 <xsl:template match="p:clays">
454 <chapter xml:id="Clays">
455 <title>Clays</title>
456 <xsl:apply-templates/>
457 </chapter>
458 </xsl:template>
460 <xsl:template match="p:clay">
461 <section>
462 <xsl:attribute name="xml:id"><xsl:value-of select="@xml:id"/></xsl:attribute>
463 <title>
464 <xsl:value-of select="@name"/>
465 <xsl:if test="@productID">,
466 <xsl:value-of select="@productID"/>
467 </xsl:if>
468 </title>
469 <para/>
470 </section>
471 </xsl:template>
473 <xsl:template match="@* | db:* | @xlink:*">
474 <xsl:copy>
475 <xsl:apply-templates select="@*|node()"/>
476 </xsl:copy>
477 </xsl:template>
479 <xsl:template match="p:recipe">
480 <informaltable>
481 <tgroup cols="2">
482 <xsl:variable name="hasReplacement" select="p:component/@replacementFor"/>
483 <thead>
484 <row>
485 <entry>Component</entry>
486 <xsl:if test="$hasReplacement">
487 <entry>Source/Replacement For</entry>
488 </xsl:if>
489 <entry>Parts</entry>
490 <entry>Price/kg for <phrase xlink:href="http://www.we.no/">Waldm. Ellefsen AS</phrase> 2003, MVA, NOK</entry>
491 </row>
492 </thead>
493 <tfoot>
494 <row>
495 <entry/>
496 <xsl:if test="sum(p:component/@parts) &lt; 100">
497 <xsl:message terminate="yes">The components for glaze <xsl:value-of select="../@name"/> amount to less than 100 parts</xsl:message>
498 </xsl:if>
499 <xsl:if test="$hasReplacement">
500 <entry/>
501 </xsl:if>
502 <entry><xsl:value-of select="sum(p:component/@parts)"/></entry>
503 <entry>
504 <xsl:variable name="componentPrices">
505 <xsl:apply-templates mode="computePrice" select="p:component"/>
506 </xsl:variable>
508 <xsl:value-of select="sum(ec:node-set($componentPrices)/*)"/>
509 </entry>
510 </row>
511 </tfoot>
512 <tbody>
513 <xsl:apply-templates select="p:component">
514 <xsl:with-param name="hasReplacement" select="$hasReplacement"/>
515 </xsl:apply-templates>
516 </tbody>
517 </tgroup>
518 </informaltable>
519 </xsl:template>
521 <xsl:template match="p:component">
522 <xsl:param name="hasReplacement"/>
524 <row>
525 <xsl:variable name="component" select="/p:pottery/p:components/p:component[@xml:id = current()/@idref]"/>
526 <xsl:call-template name="checkComponentRef">
527 <xsl:with-param name="component" select="$component"/>
528 <xsl:with-param name="name" select="@idref"/>
529 </xsl:call-template>
530 <entry><xsl:copy-of select="$component/node()"/></entry>
531 <xsl:if test="@replacementFor">
532 <xsl:variable name="replacement" select="/p:pottery/p:components/p:component[@xml:id = current()/@replacementFor]"/>
533 <xsl:call-template name="checkComponentRef">
534 <xsl:with-param name="component" select="$replacement"/>
535 <xsl:with-param name="name" select="@replacementFor"/>
536 </xsl:call-template>
537 <entry><xsl:copy-of select="$replacement/node()"/></entry>
538 </xsl:if>
540 <xsl:if test="$hasReplacement and not(@replacementFor)">
541 <entry/>
542 </xsl:if>
543 <entry><constant><xsl:value-of select="@parts"/></constant></entry>
545 <entry>
546 <xsl:apply-templates mode="computePrice" select="."/>
547 </entry>
548 </row>
549 </xsl:template>
551 <xsl:template mode="computePrice" match="p:component">
552 <constant>
553 <xsl:variable name="price" select="number(/p:pottery/p:components/p:component[@xml:id = current()/@idref]/@price)"/>
554 <xsl:variable name="priceIsFor" select="number(/p:pottery/p:components/p:component[@xml:id = current()/@idref]/@priceIsFor)"/>
556 <xsl:value-of select="((($price div ($priceIsFor div 1000.0)) * (@parts div 100.0)) * 1.25)"/>
557 </constant>
558 </xsl:template>
560 <xsl:template match="p:measurementsWhenDone">
561 <para>Measurements: height <constant><xsl:value-of select="@height"/></constant> mm,
563 <xsl:if test="@width = @depth">
564 <xsl:message>If the depth is the same as the width, the
565 depth shouldn't be specified. Detected for
566 <xsl:value-of select="../@xml:id"/></xsl:message>
567 </xsl:if>
569 <xsl:choose>
570 <xsl:when test="not(@depth)">
571 diameter <constant><xsl:value-of select="@width"/></constant> mm
572 </xsl:when>
573 <xsl:otherwise>
574 width <constant><xsl:value-of select="@width"/></constant> mm,
575 depth <constant><xsl:value-of select="@depth"/></constant> mm
576 </xsl:otherwise>
577 </xsl:choose>
578 </para>
579 </xsl:template>
581 <xsl:template name="checkComponentRef">
582 <xsl:param name="component"/>
583 <xsl:param name="name"/>
585 <xsl:if test="not($component)">
586 <xsl:message terminate="yes">Component for reference <xsl:value-of select="$name"/> couldn't be found.</xsl:message>
587 </xsl:if>
588 </xsl:template>
590 <!-- We don't use it directly. -->
591 <xsl:template match="p:samples"/>
593 <!-- Flag things we miss. -->
594 <xsl:template match="* | @*">
595 <xsl:message terminate="yes">
596 Unmatched node: <xsl:value-of select="name()"/> <xsl:value-of select="string()"/>
597 </xsl:message>
598 </xsl:template>
600 </xsl:stylesheet>
602 <!--
603 vim: et:ts=4:sw=4:sts=4