| 1 |
<?xml version='1.0'?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> |
| 3 |
|
| 4 |
<!--############################################################################ |
| 5 |
XSLT Stylesheet DocBook -> LaTeX |
| 6 |
############################################################################ --> |
| 7 |
|
| 8 |
<xsl:template match="text()"> |
| 9 |
<xsl:call-template name="scape"> |
| 10 |
<xsl:with-param name="string" select="."/> |
| 11 |
</xsl:call-template> |
| 12 |
</xsl:template> |
| 13 |
|
| 14 |
<xsl:template match="text()" mode="latex.verbatim"> |
| 15 |
<xsl:value-of select="."/> |
| 16 |
</xsl:template> |
| 17 |
|
| 18 |
<xsl:template name="do.slash.hyphen"> |
| 19 |
<xsl:param name="str"/> |
| 20 |
<xsl:choose> |
| 21 |
<xsl:when test="contains($str,'/')"> |
| 22 |
<xsl:call-template name="scape"> |
| 23 |
<xsl:with-param name="string" select="substring-before($str,'/')"/> |
| 24 |
</xsl:call-template> |
| 25 |
<xsl:text>/\-</xsl:text> |
| 26 |
<xsl:call-template name="do.slash.hyphen"> |
| 27 |
<xsl:with-param name="str" select="substring-after($str,'/')"/> |
| 28 |
</xsl:call-template> |
| 29 |
</xsl:when> |
| 30 |
<xsl:otherwise> |
| 31 |
<xsl:call-template name="scape"> |
| 32 |
<xsl:with-param name="string" select="$str"/> |
| 33 |
</xsl:call-template> |
| 34 |
</xsl:otherwise> |
| 35 |
</xsl:choose> |
| 36 |
</xsl:template> |
| 37 |
|
| 38 |
<xsl:template match="text()" mode="slash.hyphen"> |
| 39 |
<xsl:choose> |
| 40 |
<xsl:when test="contains(.,'://')"> |
| 41 |
<xsl:call-template name="scape"> |
| 42 |
<xsl:with-param name="string"> |
| 43 |
<xsl:value-of select="substring-before(.,'://')"/> |
| 44 |
</xsl:with-param> |
| 45 |
</xsl:call-template> |
| 46 |
<xsl:value-of select="'://'"/> |
| 47 |
<xsl:call-template name="do.slash.hyphen"> |
| 48 |
<xsl:with-param name="str" select="substring-after(.,'://')"/> |
| 49 |
</xsl:call-template> |
| 50 |
</xsl:when> |
| 51 |
<xsl:otherwise> |
| 52 |
<xsl:call-template name="do.slash.hyphen"> |
| 53 |
<xsl:with-param name="str" select="."/> |
| 54 |
</xsl:call-template> |
| 55 |
</xsl:otherwise> |
| 56 |
</xsl:choose> |
| 57 |
</xsl:template> |
| 58 |
|
| 59 |
|
| 60 |
<!-- Beware, we must replace some text in an escaped string --> |
| 61 |
<xsl:template name="scape.index"> |
| 62 |
<xsl:param name="string"/> |
| 63 |
<xsl:call-template name="scape-replace"> |
| 64 |
<xsl:with-param name="from">@</xsl:with-param> |
| 65 |
<xsl:with-param name="to">"@</xsl:with-param> |
| 66 |
<xsl:with-param name="string"> |
| 67 |
<xsl:call-template name="scape-replace"> |
| 68 |
<xsl:with-param name="from">!</xsl:with-param> |
| 69 |
<xsl:with-param name="to">"!</xsl:with-param> |
| 70 |
<xsl:with-param name="string"> |
| 71 |
<xsl:call-template name="scape-replace"> |
| 72 |
<xsl:with-param name="from">|</xsl:with-param> |
| 73 |
<xsl:with-param name="to">\ensuremath{"|}</xsl:with-param> |
| 74 |
<xsl:with-param name="string"> |
| 75 |
<!-- if '\{' and '\}' count is not in the same in the |
| 76 |
index term, latex indexing fails. |
| 77 |
so use a macro to avoid this side effect --> |
| 78 |
<xsl:call-template name="scape-replace"> |
| 79 |
<xsl:with-param name="from">\tbleft </xsl:with-param> |
| 80 |
<xsl:with-param name="to">\textbraceleft{}</xsl:with-param> |
| 81 |
<xsl:with-param name="string"> |
| 82 |
<xsl:call-template name="scape-replace"> |
| 83 |
<xsl:with-param name="from">\tbright </xsl:with-param> |
| 84 |
<xsl:with-param name="to">\textbraceright{}</xsl:with-param> |
| 85 |
<xsl:with-param name="string"> |
| 86 |
<!-- need two passes to avoid mess with macro ending with {} --> |
| 87 |
<xsl:call-template name="scape-replace"> |
| 88 |
<xsl:with-param name="from">{</xsl:with-param> |
| 89 |
<xsl:with-param name="to">\tbleft </xsl:with-param> |
| 90 |
<xsl:with-param name="string"> |
| 91 |
<xsl:call-template name="scape-replace"> |
| 92 |
<xsl:with-param name="from">}</xsl:with-param> |
| 93 |
<xsl:with-param name="to">\tbright </xsl:with-param> |
| 94 |
<xsl:with-param name="string"> |
| 95 |
<xsl:call-template name="scape-replace"> |
| 96 |
<xsl:with-param name="from">"</xsl:with-param> |
| 97 |
<xsl:with-param name="to">""</xsl:with-param> |
| 98 |
<xsl:with-param name="string"> |
| 99 |
<xsl:call-template name="normalize-scape"> |
| 100 |
<xsl:with-param name="string" select="$string"/> |
| 101 |
</xsl:call-template> |
| 102 |
</xsl:with-param> |
| 103 |
</xsl:call-template></xsl:with-param> |
| 104 |
</xsl:call-template></xsl:with-param> |
| 105 |
</xsl:call-template></xsl:with-param> |
| 106 |
</xsl:call-template></xsl:with-param> |
| 107 |
</xsl:call-template></xsl:with-param> |
| 108 |
</xsl:call-template></xsl:with-param> |
| 109 |
</xsl:call-template></xsl:with-param> |
| 110 |
</xsl:call-template> |
| 111 |
</xsl:template> |
| 112 |
|
| 113 |
<!-- TODO: how to scape tabs? xt plants --> |
| 114 |
<!-- If probing is required the text is silently skipped. |
| 115 |
See verbatim.xsl for an overview of the verbatim environment design |
| 116 |
that explains the need of probing. |
| 117 |
--> |
| 118 |
<xsl:template match="text()" mode="latex.programlisting"> |
| 119 |
<xsl:param name="probe" select="0"/> |
| 120 |
<xsl:if test="$probe = 0"> |
| 121 |
<xsl:value-of select="."/> |
| 122 |
</xsl:if> |
| 123 |
</xsl:template> |
| 124 |
|
| 125 |
<xsl:template name="normalize-scape" > |
| 126 |
<xsl:param name="string"/> |
| 127 |
<xsl:call-template name="scape"> |
| 128 |
<xsl:with-param name="string" select="normalize-space($string)"/> |
| 129 |
</xsl:call-template> |
| 130 |
</xsl:template> |
| 131 |
|
| 132 |
|
| 133 |
<!-- So many lines to do so little: removing spurious blank lines |
| 134 |
before and after actual text, but keeping in-between blank lines. |
| 135 |
--> |
| 136 |
<xsl:template name="normalize-border" > |
| 137 |
<xsl:param name="string"/> |
| 138 |
<xsl:param name="step" select="'start'"/> |
| 139 |
<xsl:variable name="left" select="substring-before($string,' ')"/> |
| 140 |
|
| 141 |
<xsl:choose> |
| 142 |
<xsl:when test="not(contains($string,' '))"> |
| 143 |
<xsl:value-of select="$string"/> |
| 144 |
</xsl:when> |
| 145 |
<xsl:when test="$step='start'"> |
| 146 |
<xsl:choose> |
| 147 |
<xsl:when test="string-length(normalize-space($left))=0"> |
| 148 |
<xsl:call-template name="normalize-border"> |
| 149 |
<xsl:with-param name="string" select="substring-after($string,' ')"/> |
| 150 |
<xsl:with-param name="step" select="$step"/> |
| 151 |
</xsl:call-template> |
| 152 |
</xsl:when> |
| 153 |
<xsl:otherwise> |
| 154 |
<xsl:value-of select="$left"/> |
| 155 |
<xsl:text> </xsl:text> |
| 156 |
<xsl:call-template name="normalize-border"> |
| 157 |
<xsl:with-param name="string" select="substring-after($string,' ')"/> |
| 158 |
<xsl:with-param name="step" select="'cont'"/> |
| 159 |
</xsl:call-template> |
| 160 |
</xsl:otherwise> |
| 161 |
</xsl:choose> |
| 162 |
</xsl:when> |
| 163 |
<xsl:otherwise> |
| 164 |
<xsl:value-of select="$left"/> |
| 165 |
<xsl:text> </xsl:text> |
| 166 |
<xsl:variable name="right" select="substring-after($string,' ')"/> |
| 167 |
<xsl:if test="string-length(normalize-space($right))!=0"> |
| 168 |
<xsl:call-template name="normalize-border"> |
| 169 |
<xsl:with-param name="string" select="$right"/> |
| 170 |
<xsl:with-param name="step" select="'cont'"/> |
| 171 |
</xsl:call-template> |
| 172 |
</xsl:if> |
| 173 |
</xsl:otherwise> |
| 174 |
</xsl:choose> |
| 175 |
</xsl:template> |
| 176 |
|
| 177 |
|
| 178 |
<!-- (c) David Carlisle |
| 179 |
replace all occurences of the character(s) `from' |
| 180 |
by the string `to' in the string `string'. |
| 181 |
--> |
| 182 |
<xsl:template name="string-replace" > |
| 183 |
<xsl:param name="string"/> |
| 184 |
<xsl:param name="from"/> |
| 185 |
<xsl:param name="to"/> |
| 186 |
<xsl:choose> |
| 187 |
<xsl:when test="contains($string,$from)"> |
| 188 |
<xsl:value-of select="substring-before($string,$from)"/> |
| 189 |
<xsl:value-of select="$to"/> |
| 190 |
<xsl:call-template name="string-replace"> |
| 191 |
<xsl:with-param name="string" select="substring-after($string,$from)"/> |
| 192 |
<xsl:with-param name="from" select="$from"/> |
| 193 |
<xsl:with-param name="to" select="$to"/> |
| 194 |
</xsl:call-template> |
| 195 |
</xsl:when> |
| 196 |
<xsl:otherwise> |
| 197 |
<xsl:value-of select="$string"/> |
| 198 |
</xsl:otherwise> |
| 199 |
</xsl:choose> |
| 200 |
</xsl:template> |
| 201 |
|
| 202 |
</xsl:stylesheet> |