| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<!-- |
| 3 |
Purpose: |
| 4 |
Post-process a DocBook document produced by AsciiDoctor |
| 5 |
|
| 6 |
Parameters: |
| 7 |
None |
| 8 |
|
| 9 |
Input: |
| 10 |
A DocBook 5 document |
| 11 |
|
| 12 |
Output: |
| 13 |
Changed DocBook 5 document |
| 14 |
|
| 15 |
Currently, the following corrections are made: |
| 16 |
* simpara -> para |
| 17 |
* allows GeekoDoc validation |
| 18 |
* suse2013 =< 2.0.12 display improvement |
| 19 |
* sidebar -> note |
| 20 |
* allows GeekoDoc validation |
| 21 |
* suse2013 display improvement |
| 22 |
* literallayout[@class='monospaced'] -> screen |
| 23 |
* allows GeekoDoc validation |
| 24 |
* suse2013 layout improvement |
| 25 |
* info + abstract -> info/abstract |
| 26 |
* allows DocBook validation |
| 27 |
* article/info/title -> article/title |
| 28 |
* suse2013 =< 2.0.13 display improvement, suse-xsl#397 |
| 29 |
* remove authorinitials |
| 30 |
* allows validation with GeekoDoc |
| 31 |
* fold othername into firstname and lineage into surname |
| 32 |
* allows GeekoDoc validation |
| 33 |
* neither rule should be necessary, GeekoDoc should be fixed (FIXME!) |
| 34 |
* formalpara[para/screen] and informalexample/formalpara[para/screen] -> example |
| 35 |
para/screen is not allowed in GeekoDoc |
| 36 |
|
| 37 |
Author: Thomas Schraitle <[email protected]> |
| 38 |
Copyright (C) 2018 SUSE Linux GmbH |
| 39 |
|
| 40 |
--> |
| 41 |
<!DOCTYPE xsl:stylesheet |
| 42 |
[ |
| 43 |
<!ENTITY db5ns "http://docbook.org/ns/docbook"> |
| 44 |
]> |
| 45 |
<xsl:stylesheet version="1.0" |
| 46 |
xmlns="&db5ns;" |
| 47 |
xmlns:d="&db5ns;" |
| 48 |
xmlns:xlink="http://www.w3.org/1999/xlink" |
| 49 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 50 |
|
| 51 |
<xsl:import href="../common/copy.xsl"/> |
| 52 |
<xsl:output indent="yes"/> |
| 53 |
|
| 54 |
<xsl:template match="d:authorinitials"/> |
| 55 |
<!-- othername & lineage arguably out to be supported by GeekoDoc but aren't currently. --> |
| 56 |
<xsl:template match="d:othername|d:lineage"/> |
| 57 |
<xsl:template match="d:othername|d:lineage" mode="take"> |
| 58 |
<xsl:text> </xsl:text> |
| 59 |
<xsl:apply-templates/> |
| 60 |
</xsl:template> |
| 61 |
<xsl:template match="d:firstname[following-sibling::d:othername]"> |
| 62 |
<xsl:element name="firstname" namespace="&db5ns;"> |
| 63 |
<xsl:copy-of select="@*"/> |
| 64 |
<xsl:apply-templates/> |
| 65 |
<xsl:apply-templates select="following-sibling::d:othername" mode="take"/> |
| 66 |
</xsl:element> |
| 67 |
</xsl:template> |
| 68 |
<xsl:template match="d:surname[following-sibling::d:lineage]"> |
| 69 |
<xsl:element name="surname" namespace="&db5ns;"> |
| 70 |
<xsl:copy-of select="@*"/> |
| 71 |
<xsl:apply-templates/> |
| 72 |
<xsl:apply-templates select="following-sibling::d:lineage" mode="take"/> |
| 73 |
</xsl:element> |
| 74 |
</xsl:template> |
| 75 |
|
| 76 |
<xsl:template match="d:guibutton|d:guimenuitem|d:guisubmenu"> |
| 77 |
<xsl:element name="guimenu" namespace="&db5ns;"> |
| 78 |
<xsl:copy-of select="@*"/> |
| 79 |
<xsl:apply-templates/> |
| 80 |
</xsl:element> |
| 81 |
</xsl:template> |
| 82 |
|
| 83 |
<xsl:template match="d:sidebar"> |
| 84 |
<xsl:element name="note" namespace="&db5ns;"> |
| 85 |
<xsl:copy-of select="@*"/> |
| 86 |
<xsl:apply-templates/> |
| 87 |
</xsl:element> |
| 88 |
</xsl:template> |
| 89 |
|
| 90 |
<xsl:template match="d:simpara"> |
| 91 |
<xsl:element name="para" namespace="&db5ns;"> |
| 92 |
<xsl:copy-of select="@*"/> |
| 93 |
<xsl:apply-templates/> |
| 94 |
</xsl:element> |
| 95 |
</xsl:template> |
| 96 |
|
| 97 |
<xsl:template match="d:literallayout[@class='monospaced']|d:programlisting"> |
| 98 |
<xsl:element name="screen" namespace="&db5ns;"> |
| 99 |
<xsl:copy-of select="@*[local-name()!='class']"/> |
| 100 |
<xsl:apply-templates/> |
| 101 |
</xsl:element> |
| 102 |
</xsl:template> |
| 103 |
|
| 104 |
<xsl:template match="d:imagedata"> |
| 105 |
<xsl:copy> |
| 106 |
<xsl:copy-of select="@*[local-name() != 'contentwidth']"/> |
| 107 |
<xsl:choose> |
| 108 |
<xsl:when test="@width"> |
| 109 |
<xsl:copy-of select="@width"/> |
| 110 |
</xsl:when> |
| 111 |
<xsl:otherwise> |
| 112 |
<xsl:attribute name="width"> |
| 113 |
<xsl:value-of select="@contentwidth"/> |
| 114 |
</xsl:attribute> |
| 115 |
</xsl:otherwise> |
| 116 |
</xsl:choose> |
| 117 |
</xsl:copy> |
| 118 |
</xsl:template> |
| 119 |
|
| 120 |
<xsl:template match="d:abstract[not(ancestor::d:info)]"/> |
| 121 |
<xsl:template match="d:info[following-sibling::d:abstract]"> |
| 122 |
<xsl:element name="{local-name(.)}" namespace="&db5ns;"> |
| 123 |
<xsl:apply-templates select="@*|node()"/> |
| 124 |
<xsl:apply-templates select="following-sibling::d:abstract" mode="copy-element"/> |
| 125 |
</xsl:element> |
| 126 |
</xsl:template> |
| 127 |
|
| 128 |
<xsl:template match="*" mode="copy-element"> |
| 129 |
<xsl:element name="{local-name(.)}" namespace="&db5ns;"> |
| 130 |
<xsl:apply-templates select="@*|node()"/> |
| 131 |
</xsl:element> |
| 132 |
</xsl:template> |
| 133 |
|
| 134 |
<xsl:template match="d:article/d:info/d:title|d:article/d:info/d:subtitle"/> |
| 135 |
<xsl:template match="d:article[d:info/d:title|d:info/d:subtitle]"> |
| 136 |
<xsl:element name="{local-name(.)}" namespace="&db5ns;"> |
| 137 |
<xsl:apply-templates select="@*"/> |
| 138 |
<xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="copy-element"/> |
| 139 |
<xsl:apply-templates select="(d:subtitle|d:info/d:subtitle)[1]" mode="copy-element"/> |
| 140 |
<xsl:apply-templates select="node()[not(self::d:title or self::d:subtitle)]"/> |
| 141 |
</xsl:element> |
| 142 |
</xsl:template> |
| 143 |
|
| 144 |
<xsl:template match="d:link[@linkend]"> |
| 145 |
<xsl:call-template name="make-xref"> |
| 146 |
<xsl:with-param name="linkend" select="normalize-space(@linkend)"/> |
| 147 |
<xsl:with-param name="text" select="."/> |
| 148 |
</xsl:call-template> |
| 149 |
</xsl:template> |
| 150 |
|
| 151 |
<xsl:template match="d:link[starts-with(@xlink:href, '#')]"> |
| 152 |
<xsl:call-template name="make-xref"> |
| 153 |
<xsl:with-param name="linkend" select="normalize-space(substring-after(@xlink:href, '#'))"/> |
| 154 |
<xsl:with-param name="text" select="."/> |
| 155 |
</xsl:call-template> |
| 156 |
</xsl:template> |
| 157 |
|
| 158 |
<xsl:template name="make-xref"> |
| 159 |
<xsl:param name="linkend" select="''"/> |
| 160 |
<xsl:param name="text" select="''"/> |
| 161 |
|
| 162 |
<xsl:if test="normalize-space($text)"> |
| 163 |
<xsl:value-of select="$text"/> |
| 164 |
<xsl:text> (</xsl:text> |
| 165 |
</xsl:if> |
| 166 |
<xsl:element name="xref"> |
| 167 |
<xsl:attribute name="linkend"> |
| 168 |
<xsl:value-of select="$linkend"/> |
| 169 |
</xsl:attribute> |
| 170 |
</xsl:element> |
| 171 |
<xsl:if test="normalize-space($text)"> |
| 172 |
<xsl:text>)</xsl:text> |
| 173 |
</xsl:if> |
| 174 |
</xsl:template> |
| 175 |
|
| 176 |
|
| 177 |
<!-- |
| 178 |
A correctly-formatted AsciiDoc example with a screen would look like this |
| 179 |
(be aware that the − characters are minuses, not normal hyphens, do not |
| 180 |
copy the examples!): |
| 181 |
|
| 182 |
.Title of example 1 (correct) |
| 183 |
==== |
| 184 |
−−−− |
| 185 |
command -option='value' |
| 186 |
−−−− |
| 187 |
==== |
| 188 |
|
| 189 |
=> <example><title>Title...</title><screen>command...</screen></example> |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
However, authors are creative and came up with the following variants as well: |
| 194 |
|
| 195 |
.Title of example 2 (bad) |
| 196 |
−−−− |
| 197 |
command -option='value' |
| 198 |
−−−− |
| 199 |
|
| 200 |
=> <formalpara><title>Title...</title><screen>command...</screen></formalpara> |
| 201 |
|
| 202 |
|
| 203 |
==== |
| 204 |
.Title of example 3 (bad) |
| 205 |
−−−− |
| 206 |
command -option='value' |
| 207 |
−−−− |
| 208 |
==== |
| 209 |
|
| 210 |
=> <informalexample><formalpara><title>Title...</title><screen>command...</screen></formalpara></informalexample> |
| 211 |
|
| 212 |
|
| 213 |
While the syntax of example (2) does not support more elements before/after |
| 214 |
the screen, example (3) unfortunately does. For example, there could be |
| 215 |
multiple formalparas that are generated within the `====` block of |
| 216 |
example (3). This would mean, we may need to apply both the rule for |
| 217 |
example (3) and the rule for example (2) successively. |
| 218 |
|
| 219 |
--> |
| 220 |
|
| 221 |
<xsl:template match="d:formalpara[d:para/d:screen| |
| 222 |
d:para/d:literallayout[@class='monospaced']]"> |
| 223 |
<xsl:element name="example" namespace="&db5ns;"> |
| 224 |
<xsl:apply-templates select="d:title"/> |
| 225 |
<!-- The following apply-templates is not relevant for any of the cases |
| 226 |
we know, it is meant as a defensive measure against unknown cases. The |
| 227 |
output of the templates is unlikely to correctly order para content and |
| 228 |
the screen but at least we get it all into the output document. --> |
| 229 |
<xsl:apply-templates select="d:para" mode="exclude-verbatim"/> |
| 230 |
<xsl:apply-templates select="d:para/d:screen| |
| 231 |
d:para/d:literallayout[@class='monospaced']"/> |
| 232 |
</xsl:element> |
| 233 |
</xsl:template> |
| 234 |
|
| 235 |
<xsl:template match="d:informalexample[d:*[1][self::d:formalpara] |
| 236 |
[d:para/d:screen| |
| 237 |
d:para/d:literallayout[@class='monospaced']]]"> |
| 238 |
<xsl:element name="example" namespace="&db5ns;"> |
| 239 |
<xsl:apply-templates select="@*"/> |
| 240 |
<xsl:apply-templates select="d:formalpara[1]/d:title"/> |
| 241 |
<!-- The following apply-templates is not relevant for any of the cases |
| 242 |
we know, it is meant as a defensive measure against unknown cases. The |
| 243 |
output of the templates is unlikely to correctly order para content and |
| 244 |
the screen but at least we get it all into the output document. --> |
| 245 |
<xsl:apply-templates select="d:formalpara[1]/d:para" mode="exclude-verbatim"/> |
| 246 |
<xsl:apply-templates select="d:formalpara[1]/d:para/d:screen| |
| 247 |
d:formalpara[1]/d:para/d:literallayout[@class='monospaced']"/> |
| 248 |
<xsl:apply-templates select="d:*[position() > 1]|node()[not(*)]"/> |
| 249 |
</xsl:element> |
| 250 |
</xsl:template> |
| 251 |
|
| 252 |
<xsl:template match="d:para" mode="exclude-verbatim"> |
| 253 |
<xsl:if test="*[not(self::d:screen|self::d:literallayout[@class='monospaced'])] or |
| 254 |
text()[normalize-space(.) != '']"> |
| 255 |
<xsl:copy> |
| 256 |
<xsl:apply-templates select="@*|node()[not(self::d:screen| |
| 257 |
self::d:literallayout[@class='monospaced'])]"/> |
| 258 |
</xsl:copy> |
| 259 |
</xsl:if> |
| 260 |
</xsl:template> |
| 261 |
|
| 262 |
</xsl:stylesheet> |