| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 3 |
xmlns:exsl="http://exslt.org/common" |
| 4 |
exclude-result-prefixes="exsl" |
| 5 |
version='1.0'> |
| 6 |
|
| 7 |
<!--############################################################################ |
| 8 |
XSLT Stylesheet DocBook -> LaTeX |
| 9 |
############################################################################ |
| 10 |
|
| 11 |
This stylesheet allows to setup paper and page dimensions through some |
| 12 |
predefined parameters. Most of the page setup parameters come from the |
| 13 |
DocBook XSL FO parameters. The latex packages used to perform this setup |
| 14 |
are the well known 'geometry' and 'crop'. |
| 15 |
|
| 16 |
This feature has been sponsored by Freexian (http://www.freexian.com). |
| 17 |
|
| 18 |
--> |
| 19 |
<xsl:param name="page.height"/> |
| 20 |
<xsl:param name="page.margin.bottom"/> |
| 21 |
<xsl:param name="page.margin.inner"/> |
| 22 |
<xsl:param name="page.margin.outer"/> |
| 23 |
<xsl:param name="page.margin.top"/> |
| 24 |
<xsl:param name="page.width"/> |
| 25 |
<xsl:param name="paper.type"/> |
| 26 |
<xsl:param name="geometry.options"/> |
| 27 |
<xsl:param name="crop.marks" select="0"/> |
| 28 |
<xsl:param name="crop.paper.type"/> |
| 29 |
<xsl:param name="crop.page.width"/> |
| 30 |
<xsl:param name="crop.page.height"/> |
| 31 |
<xsl:param name="crop.mode" select="'cam'"/> |
| 32 |
<xsl:param name="crop.options"/> |
| 33 |
|
| 34 |
<xsl:template name="page.setup"> |
| 35 |
|
| 36 |
<xsl:variable name="geometry.setup"> |
| 37 |
<geometry paperwidth="{$page.width}" |
| 38 |
paperheight="{$page.height}" |
| 39 |
papername="{$paper.type}" |
| 40 |
right="{$page.margin.outer}" |
| 41 |
left="{$page.margin.inner}" |
| 42 |
top="{$page.margin.top}" |
| 43 |
bottom="{$page.margin.bottom}"/> |
| 44 |
</xsl:variable> |
| 45 |
|
| 46 |
<xsl:variable name="geometry.params"> |
| 47 |
<xsl:for-each select="exsl:node-set($geometry.setup)//@*"> |
| 48 |
<xsl:if test=". != ''"> |
| 49 |
<xsl:value-of select="local-name()"/> |
| 50 |
<xsl:text>=</xsl:text> |
| 51 |
<xsl:value-of select="."/> |
| 52 |
<xsl:text>,</xsl:text> |
| 53 |
</xsl:if> |
| 54 |
</xsl:for-each> |
| 55 |
<xsl:value-of select="$geometry.options"/> |
| 56 |
</xsl:variable> |
| 57 |
|
| 58 |
<!-- The body includes the header and footer --> |
| 59 |
<xsl:if test="$geometry.params != ''"> |
| 60 |
<xsl:text>\usepackage[includeheadfoot,</xsl:text> |
| 61 |
<xsl:value-of select="$geometry.params"/> |
| 62 |
<xsl:text>]{geometry} </xsl:text> |
| 63 |
</xsl:if> |
| 64 |
|
| 65 |
<xsl:if test="$crop.marks != 0"> |
| 66 |
<xsl:variable name="crop.params"> |
| 67 |
<xsl:choose> |
| 68 |
<xsl:when test="$crop.paper.type != ''"> |
| 69 |
<xsl:value-of select="$crop.paper.type"/> |
| 70 |
<xsl:text>,</xsl:text> |
| 71 |
</xsl:when> |
| 72 |
<xsl:when test="$crop.page.width != '' and |
| 73 |
$crop.page.height != ''"> |
| 74 |
<!-- No 'true' length, assuming no scaling --> |
| 75 |
<xsl:text>width=</xsl:text> |
| 76 |
<xsl:value-of select="$crop.page.width"/> |
| 77 |
<xsl:text>,</xsl:text> |
| 78 |
<xsl:text>height=</xsl:text> |
| 79 |
<xsl:value-of select="$crop.page.height"/> |
| 80 |
<xsl:text>,</xsl:text> |
| 81 |
</xsl:when> |
| 82 |
<xsl:otherwise> |
| 83 |
<xsl:message> |
| 84 |
<xsl:text>Warning: crop required without crop size setup</xsl:text> |
| 85 |
</xsl:message> |
| 86 |
</xsl:otherwise> |
| 87 |
|
| 88 |
<!-- FIXME: find out how to use crop.margin. The following fails: |
| 89 |
<xsl:otherwise> |
| 90 |
<xsl:text>width=\pagewidth</xsl:text> |
| 91 |
<xsl:text>+</xsl:text> |
| 92 |
<xsl:value-of select="$crop.margin"/> |
| 93 |
<xsl:text>+</xsl:text> |
| 94 |
<xsl:value-of select="$crop.margin"/> |
| 95 |
<xsl:text>,</xsl:text> |
| 96 |
<xsl:text>height=\pageheight</xsl:text> |
| 97 |
<xsl:text>+</xsl:text> |
| 98 |
<xsl:value-of select="$crop.margin"/> |
| 99 |
<xsl:text>+</xsl:text> |
| 100 |
<xsl:value-of select="$crop.margin"/> |
| 101 |
<xsl:text>,</xsl:text> |
| 102 |
</xsl:otherwise> |
| 103 |
--> |
| 104 |
</xsl:choose> |
| 105 |
<xsl:value-of select="$crop.options"/> |
| 106 |
</xsl:variable> |
| 107 |
|
| 108 |
<xsl:if test="$crop.params != ''"> |
| 109 |
<xsl:text>\usepackage[</xsl:text> |
| 110 |
<xsl:value-of select="$crop.params"/> |
| 111 |
<xsl:text>center,</xsl:text> |
| 112 |
<xsl:value-of select="$crop.mode"/> |
| 113 |
<xsl:text>]{crop} </xsl:text> |
| 114 |
</xsl:if> |
| 115 |
</xsl:if> |
| 116 |
|
| 117 |
</xsl:template> |
| 118 |
|
| 119 |
<!-- Unit-test cases: |
| 120 |
dblatex -P paper.type=a5paper |
| 121 |
-P page.margin.outer=1cm |
| 122 |
-P page.margin.inner=3cm pagesetup.xml |
| 123 |
|
| 124 |
dblatex -P paper.type=a5paper |
| 125 |
-P page.margin.outer=1cm |
| 126 |
-P page.margin.inner=3cm |
| 127 |
-P crop.marks=1 |
| 128 |
-P crop.paper.type=a4 pagesetup.xml |
| 129 |
|
| 130 |
dblatex -P page.width=18.89cm |
| 131 |
-P page.height=24.58cm |
| 132 |
-P page.margin.outer=1cm |
| 133 |
-P page.margin.inner=3cm |
| 134 |
-P crop.marks=1 |
| 135 |
-P crop.page.width=21cm |
| 136 |
-P crop.page.height=29.7cm pagesetup.xml |
| 137 |
--> |
| 138 |
</xsl:stylesheet> |