- Timestamp:
- Mar 21, 2023 4:27:41 PM (19 months ago)
- Location:
- trunk/doc/manual
- Files:
-
- 2 copied
-
docbook-refentry-to-manual-dita-pre.xsl (copied) (copied from trunk/doc/manual/docbook-refentry-to-manual-sect1.xsl ) (4 diffs)
-
docbook-refentry-to-manual-dita.xsl (copied) (copied from trunk/doc/manual/docbook-refentry-to-manual-sect1.xsl ) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/docbook-refentry-to-manual-dita-pre.xsl
r99081 r99099 1 1 <?xml version="1.0"?> 2 2 <!-- 3 docbook-refentry-to-manual-sect1.xsl: 4 XSLT stylesheet for transforming a refentry (manpage) 5 to a sect1 for the user manual. 3 docbook-refentry-to-manual-dita-pre.xsl: 4 XSLT stylesheet for preprocessing a refentry (manpage) 5 before converting it to dita for use in the user manual. 6 7 This just applies remark elements. 6 8 --> 7 9 <!-- … … 40 42 41 43 <!-- - - - - - - - - - - - - - - - - - - - - - - 42 global XSLT variables43 - - - - - - - - - - - - - - - - - - - - - - -->44 45 46 47 <!-- - - - - - - - - - - - - - - - - - - - - - -48 44 base operation is to copy. 49 45 - - - - - - - - - - - - - - - - - - - - - - --> … … 55 51 </xsl:template> 56 52 57 58 <!-- - - - - - - - - - - - - - - - - - - - - - -59 60 - - - - - - - - - - - - - - - - - - - - - - -->61 62 <!-- rename refentry to sect1 -->63 <xsl:template match="refentry">64 <xsl:element name="sect1">65 <xsl:attribute name="condition">refentry</xsl:attribute>66 <xsl:apply-templates select="node()|@*"/>67 </xsl:element>68 </xsl:template>69 70 <!-- Remove refentryinfo, keeping the title element. -->71 <xsl:template match="refentryinfo">72 <xsl:if test="./title">73 <xsl:copy-of select="./title"/>74 </xsl:if>75 </xsl:template>76 77 <!-- Morph refnamediv into a brief description. -->78 <xsl:template match="refnamediv">79 <xsl:element name="para">80 <xsl:call-template name="capitalize">81 <xsl:with-param name="text" select="normalize-space(./refpurpose)"/>82 </xsl:call-template>83 <xsl:text>.</xsl:text>84 </xsl:element>85 </xsl:template>86 87 <!-- Morph the refsynopsisdiv part into a synopsis section. -->88 <xsl:template match="refsynopsisdiv">89 <xsl:if test="name(*[1]) != 'cmdsynopsis'"><xsl:message terminate="yes">Expected refsynopsisdiv to start with cmdsynopsis</xsl:message></xsl:if>90 <xsl:if test="title"><xsl:message terminate="yes">No title element supported in refsynopsisdiv</xsl:message></xsl:if>91 92 <xsl:element name="sect2">93 <xsl:attribute name="role">not-in-toc</xsl:attribute>94 <xsl:attribute name="condition">refsynopsisdiv</xsl:attribute>95 <xsl:element name="title">96 <xsl:text>Synopsis</xsl:text>97 </xsl:element>98 <xsl:apply-templates />99 </xsl:element>100 101 </xsl:template>102 103 <!-- refsect1 -> sect2 -->104 <xsl:template match="refsect1">105 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect1 requires title</xsl:message></xsl:if>106 <xsl:element name="sect2">107 <xsl:attribute name="role">not-in-toc</xsl:attribute>108 <xsl:attribute name="condition">refsect1</xsl:attribute>109 <xsl:if test="@id">110 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>111 </xsl:if>112 <xsl:apply-templates />113 </xsl:element>114 </xsl:template>115 116 <!-- refsect2 -> sect3 -->117 <xsl:template match="refsect2">118 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect2 requires title</xsl:message></xsl:if>119 <xsl:element name="sect3">120 <xsl:attribute name="role">not-in-toc</xsl:attribute>121 <xsl:attribute name="condition">refsect2</xsl:attribute>122 <xsl:if test="@id">123 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>124 </xsl:if>125 <xsl:apply-templates />126 </xsl:element>127 </xsl:template>128 129 <!-- refsect3 -> sect4 -->130 <xsl:template match="refsect3">131 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect3 requires title</xsl:message></xsl:if>132 <xsl:element name="sect4">133 <xsl:attribute name="role">not-in-toc</xsl:attribute>134 <xsl:attribute name="condition">refsect3</xsl:attribute>135 <xsl:if test="@id">136 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>137 </xsl:if>138 <xsl:apply-templates />139 </xsl:element>140 </xsl:template>141 142 143 <!-- Remove refmeta. -->144 <xsl:template match="refmeta"/>145 53 146 54 <!-- … … 169 77 </xsl:template> 170 78 171 <!--172 Captializes the given text.173 -->174 <xsl:template name="capitalize">175 <xsl:param name="text"/>176 <xsl:call-template name="str:to-upper">177 <xsl:with-param name="text" select="substring($text,1,1)"/>178 </xsl:call-template>179 <xsl:value-of select="substring($text,2)"/>180 </xsl:template>181 79 182 80 </xsl:stylesheet> -
trunk/doc/manual/docbook-refentry-to-manual-dita.xsl
r99081 r99099 2 2 <!-- 3 3 docbook-refentry-to-manual-sect1.xsl: 4 XSLT stylesheet for transforming a refentry (manpage)5 to a sect1 forthe user manual.4 XSLT stylesheet for converting a refentry (manpage) 5 to dita for use in the user manual. 6 6 --> 7 7 <!-- … … 46 46 47 47 <!-- - - - - - - - - - - - - - - - - - - - - - - 48 base operation is to copy.48 base operation is to fail on nodes w/o explicit matching. 49 49 - - - - - - - - - - - - - - - - - - - - - - --> 50 50 51 <xsl:template match="node()|@*"> 52 <xsl:copy> 53 <xsl:apply-templates select="node()|@*"/> 54 </xsl:copy> 51 <xsl:template match="*"> 52 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>unhandled element</xsl:message> 55 53 </xsl:template> 56 54 57 55 58 56 <!-- - - - - - - - - - - - - - - - - - - - - - - 59 57 transformations starting with root and going deeper. 60 58 - - - - - - - - - - - - - - - - - - - - - - --> 61 59 62 <!-- rename refentry to sect1 --> 60 <!-- Rename refentry to reference. 61 Also we need to wrap the refsync and refsect1 elements in a refbody. --> 63 62 <xsl:template match="refentry"> 64 <xsl:element name="sect1"> 65 <xsl:attribute name="condition">refentry</xsl:attribute> 66 <xsl:apply-templates select="node()|@*"/> 67 </xsl:element> 68 </xsl:template> 69 70 <!-- Remove refentryinfo, keeping the title element. --> 71 <xsl:template match="refentryinfo"> 72 <xsl:if test="./title"> 73 <xsl:copy-of select="./title"/> 74 </xsl:if> 75 </xsl:template> 76 77 <!-- Morph refnamediv into a brief description. --> 78 <xsl:template match="refnamediv"> 79 <xsl:element name="para"> 80 <xsl:call-template name="capitalize"> 81 <xsl:with-param name="text" select="normalize-space(./refpurpose)"/> 82 </xsl:call-template> 83 <xsl:text>.</xsl:text> 84 </xsl:element> 85 </xsl:template> 86 87 <!-- Morph the refsynopsisdiv part into a synopsis section. --> 63 <xsl:text disable-output-escaping='yes'><!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd"></xsl:text> 64 65 <xsl:element name="reference"> 66 <xsl:if test="not(@id)"> 67 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>refentry must have an id attribute!</xsl:message> 68 </xsl:if> 69 <xsl:attribute name="rev">refentry</xsl:attribute> 70 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> 71 72 <!-- Copy title element from refentryinfo --> 73 <xsl:if test="./refentryinfo/title"> 74 <xsl:copy-of select="./refentryinfo/title"/> 75 </xsl:if> 76 77 <!-- Create a shortdesc element from the text in refnamediv/refpurpose --> 78 <xsl:if test="./refnamediv/refpurpose"> 79 <xsl:element name="shortdesc"> 80 <xsl:attribute name="rev">refnamediv/refpurpose</xsl:attribute> 81 <xsl:call-template name="capitalize"> 82 <xsl:with-param name="text" select="normalize-space(./refnamediv/refpurpose)"/> 83 </xsl:call-template> 84 </xsl:element> 85 </xsl:if> 86 87 <!-- Put everything else side a refbody element --> 88 <xsl:element name="refbody"> 89 <xsl:apply-templates /> 90 </xsl:element> 91 92 </xsl:element> 93 </xsl:template> 94 95 <!-- Remove refentryinfo (we extracted the title element already). --> 96 <xsl:template match="refentryinfo" /> 97 98 <!-- Remove refmeta (manpage info). --> 99 <xsl:template match="refmeta"/> 100 101 <!-- Remove the refnamediv (we extracted a shortdesc from it already). --> 102 <xsl:template match="refnamediv"/> 103 104 <!-- Morph the refsynopsisdiv part into a refsyn section. --> 88 105 <xsl:template match="refsynopsisdiv"> 89 106 <xsl:if test="name(*[1]) != 'cmdsynopsis'"><xsl:message terminate="yes">Expected refsynopsisdiv to start with cmdsynopsis</xsl:message></xsl:if> 90 107 <xsl:if test="title"><xsl:message terminate="yes">No title element supported in refsynopsisdiv</xsl:message></xsl:if> 91 108 92 <xsl:element name="sect2"> 93 <xsl:attribute name="role">not-in-toc</xsl:attribute> 94 <xsl:attribute name="condition">refsynopsisdiv</xsl:attribute> 109 <xsl:element name="refsyn"> 110 <xsl:attribute name="rev">refsynopsisdiv</xsl:attribute> 95 111 <xsl:element name="title"> 96 <xsl:text>Synopsis</xsl:text>112 <xsl:text>Synopsis</xsl:text> 97 113 </xsl:element> 98 114 <xsl:apply-templates /> … … 101 117 </xsl:template> 102 118 103 <!-- refsect1 -> sect 2-->119 <!-- refsect1 -> section --> 104 120 <xsl:template match="refsect1"> 105 121 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect1 requires title</xsl:message></xsl:if> 106 <xsl:element name="sect2"> 107 <xsl:attribute name="role">not-in-toc</xsl:attribute> 108 <xsl:attribute name="condition">refsect1</xsl:attribute> 122 <xsl:element name="section"> 123 <xsl:attribute name="rev">refsect1</xsl:attribute> 109 124 <xsl:if test="@id"> 110 125 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> … … 114 129 </xsl:template> 115 130 116 <!-- refsect2 -> sect 3-->131 <!-- refsect2 -> sectiondiv. --> 117 132 <xsl:template match="refsect2"> 118 133 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect2 requires title</xsl:message></xsl:if> 119 <xsl:element name="sect3"> 120 <xsl:attribute name="role">not-in-toc</xsl:attribute> 121 <xsl:attribute name="condition">refsect2</xsl:attribute> 134 <xsl:element name="sectiondiv"> 135 <xsl:attribute name="rev">refsect2</xsl:attribute> 122 136 <xsl:if test="@id"> 123 137 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> 124 138 </xsl:if> 125 <xsl:apply-templates /> 126 </xsl:element> 127 </xsl:template> 128 129 <!-- refsect3 -> sect4 --> 130 <xsl:template match="refsect3"> 131 <xsl:if test="not(title)"><xsl:message terminate="yes">refsect3 requires title</xsl:message></xsl:if> 132 <xsl:element name="sect4"> 133 <xsl:attribute name="role">not-in-toc</xsl:attribute> 134 <xsl:attribute name="condition">refsect3</xsl:attribute> 139 140 <xsl:apply-templates /> 141 142 </xsl:element> 143 </xsl:template> 144 145 <!-- refsect2/title -> b --> 146 <xsl:template match="refsect2/title"> 147 <xsl:element name="b"> 148 <xsl:attribute name="rev">refsect2/title</xsl:attribute> 149 <xsl:apply-templates /> 150 </xsl:element> 151 </xsl:template> 152 153 <!-- refsect1/title -> title --> 154 <xsl:template match="refsect1/title"> 155 <xsl:copy> 156 <xsl:apply-templates /> 157 </xsl:copy> 158 </xsl:template> 159 160 <!-- para -> p --> 161 <xsl:template match="para"> 162 <xsl:element name="p"> 163 <xsl:attribute name="rev">para</xsl:attribute> 164 <xsl:apply-templates /> 165 </xsl:element> 166 </xsl:template> 167 168 <!-- note in a section -> note (no change needed) --> 169 <xsl:template match="refsect1/note | refsect2/note"> 170 <xsl:copy> 171 <xsl:apply-templates /> 172 </xsl:copy> 173 </xsl:template> 174 175 <!-- variablelist -> dl --> 176 <xsl:template match="variablelist"> 177 <xsl:element name="dl"> 178 <xsl:attribute name="rev">variablelist</xsl:attribute> 179 <xsl:apply-templates /> 180 </xsl:element> 181 </xsl:template> 182 183 <!-- varlistentry -> dlentry --> 184 <xsl:template match="varlistentry"> 185 <xsl:element name="dlentry"> 186 <xsl:attribute name="rev">varlistentry</xsl:attribute> 187 <xsl:apply-templates /> 188 </xsl:element> 189 </xsl:template> 190 191 <!-- term (in varlistentry) -> dt --> 192 <xsl:template match="varlistentry/term"> 193 <xsl:element name="dt"> 194 <xsl:attribute name="rev">term</xsl:attribute> 195 <xsl:apply-templates /> 196 </xsl:element> 197 </xsl:template> 198 199 <!-- listitem (in varlistentry) -> dd --> 200 <xsl:template match="varlistentry/listitem"> 201 <xsl:element name="dd"> 202 <xsl:attribute name="rev">listitem</xsl:attribute> 203 <xsl:apply-templates /> 204 </xsl:element> 205 </xsl:template> 206 207 <!-- itemizedlist -> ul --> 208 <xsl:template match="itemizedlist"> 209 <xsl:element name="ul"> 210 <xsl:attribute name="rev">itemizedlist</xsl:attribute> 211 <xsl:apply-templates /> 212 </xsl:element> 213 </xsl:template> 214 215 <!-- listitem in itemizedlist -> li --> 216 <xsl:template match="itemizedlist/listitem"> 217 <xsl:element name="li"> 218 <xsl:attribute name="rev">listitem</xsl:attribute> 219 <xsl:apply-templates /> 220 </xsl:element> 221 </xsl:template> 222 223 <!-- command in cmdsynopsis -> syntaxdiagram --> 224 <xsl:template match="cmdsynopsis"> 225 <xsl:element name="syntaxdiagram"> 226 <xsl:attribute name="rev">cmdsynopsis</xsl:attribute> 135 227 <xsl:if test="@id"> 136 228 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> … … 140 232 </xsl:template> 141 233 142 143 <!-- Remove refmeta. --> 144 <xsl:template match="refmeta"/> 234 <!-- command in cmdsynopsis -> groupseq + kwd --> 235 <xsl:template match="cmdsynopsis/command | cmdsynopsis/*/command" > 236 <xsl:element name="groupseq"> 237 <xsl:attribute name="rev">command</xsl:attribute> 238 <xsl:element name="kwd"> 239 <xsl:attribute name="rev">command</xsl:attribute> 240 <xsl:apply-templates /> 241 </xsl:element> 242 </xsl:element> 243 </xsl:template> 244 245 <!-- command in not cmdsynopsis -> userinput --> 246 <xsl:template match="command"> 247 <xsl:element name="userinput"> 248 <xsl:attribute name="rev">command</xsl:attribute> 249 <xsl:apply-templates /> 250 </xsl:element> 251 </xsl:template> 252 253 <!-- arg --> 254 <xsl:template match="arg/text()"> 255 <xsl:element name="kwd"> 256 <xsl:attribute name="rev">arg</xsl:attribute> 257 <xsl:value-of select="."/> 258 </xsl:element> 259 </xsl:template> 260 261 <xsl:template match="arg[(not(@choice) or @choice='opt') and (not(@rep) or @rep='norepeat')]" > 262 <xsl:element name="groupseq"> 263 <xsl:attribute name="rev">arg[opt,norepeat]</xsl:attribute> 264 <xsl:attribute name="importance">optional</xsl:attribute> 265 <xsl:apply-templates /> 266 </xsl:element> 267 </xsl:template> 268 269 <xsl:template match="arg[@choice='req' and (not(@rep) or @rep='norepeat')]" > 270 <xsl:element name="groupseq"> 271 <xsl:attribute name="rev">arg[req,norepeat]</xsl:attribute> 272 <xsl:attribute name="importance">required</xsl:attribute> 273 <xsl:apply-templates /> 274 </xsl:element> 275 </xsl:template> 276 277 <xsl:template match="arg[@choice='plain' and (not(@rep) or @rep='norepeat')]" > 278 <xsl:if test="./*"> 279 <xsl:message terminate="yes"><xsl:call-template name="error-prefix"/>Expected only text under arg[choice=plain]</xsl:message> 280 </xsl:if> 281 <xsl:element name="kwd"> 282 <xsl:attribute name="rev">arg[plain]</xsl:attribute> 283 <xsl:value-of select="."/> 284 </xsl:element> 285 </xsl:template> 286 287 <!-- replaceable under arg -> var --> 288 <xsl:template match="arg/replaceable" > 289 <xsl:element name="var"> 290 <xsl:attribute name="rev">replaceable</xsl:attribute> 291 <xsl:apply-templates /> 292 </xsl:element> 293 </xsl:template> 294 295 <!-- replaceable in para or term -> synph+var --> 296 <xsl:template match="para/replaceable | term/replaceable" > 297 <xsl:element name="synph"> 298 <xsl:attribute name="rev">replaceable</xsl:attribute> 299 <xsl:element name="var"> 300 <xsl:attribute name="rev">replaceable</xsl:attribute> 301 <xsl:apply-templates /> 302 </xsl:element> 303 </xsl:element> 304 </xsl:template> 305 306 <!-- replaceable in option -> var --> 307 <xsl:template match="option/replaceable" > 308 <xsl:element name="var"> 309 <xsl:attribute name="rev">option/replaceable</xsl:attribute> 310 <xsl:apply-templates /> 311 </xsl:element> 312 </xsl:template> 313 314 <!-- group under cmdsynopsis -> groupchoice --> 315 <xsl:template match="arg/group[@choice='plain'] | cmdsynopsis/group[@choice='plain']"> 316 <xsl:element name="groupchoice"> 317 <xsl:attribute name="rev">group</xsl:attribute> 318 <xsl:apply-templates /> 319 </xsl:element> 320 </xsl:template> 321 322 323 <!-- option --> 324 <xsl:template match="option/text()" > 325 <xsl:element name="kwd"> 326 <xsl:attribute name="rev">option</xsl:attribute> 327 <xsl:value-of select="."/> 328 </xsl:element> 329 </xsl:template> 330 331 <xsl:template match="option" > 332 <xsl:element name="synph"> 333 <xsl:attribute name="rev">option</xsl:attribute> 334 <xsl:apply-templates /> 335 </xsl:element> 336 </xsl:template> 337 338 <!-- literal -> codeph --> 339 <xsl:template match="literal" > 340 <xsl:element name="codeph"> 341 <xsl:attribute name="rev">literal</xsl:attribute> 342 <xsl:apply-templates /> 343 </xsl:element> 344 </xsl:template> 345 346 <!-- filename -> filepath --> 347 <xsl:template match="filename" > 348 <xsl:element name="filepath"> 349 <xsl:attribute name="rev">filename</xsl:attribute> 350 <xsl:apply-templates /> 351 </xsl:element> 352 </xsl:template> 353 354 <!-- screen - pass thru --> 355 <xsl:template match="screen" > 356 <xsl:copy> 357 <xsl:apply-templates /> 358 </xsl:copy> 359 </xsl:template> 360 361 145 362 146 363 <!-- … … 150 367 <xsl:template match="remark"/> 151 368 152 <!-- help-manual - stuff that should only be included in the manual. -->153 <xsl:template match="remark[@role = 'help-manual']">154 <xsl:apply-templates/>155 </xsl:template>156 157 <!-- help-copy-synopsis - used in refsect2 to copy synopsis from the refsynopsisdiv. -->158 <xsl:template match="remark[@role = 'help-copy-synopsis']">159 <xsl:if test="not(parent::refsect2)">160 <xsl:message terminate="yes">The help-copy-synopsis remark is only applicable in refsect2.</xsl:message>161 </xsl:if>162 <xsl:variable name="sSrcId" select="concat('synopsis-',../@id)"/>163 <xsl:if test="not(/refentry/refsynopsisdiv/cmdsynopsis[@id = $sSrcId])">164 <xsl:message terminate="yes">Could not find any cmdsynopsis with id=<xsl:value-of select="$sSrcId"/> in refsynopsisdiv.</xsl:message>165 </xsl:if>166 <xsl:element name="cmdsynopsis">167 <xsl:copy-of select="/refentry/refsynopsisdiv/cmdsynopsis[@id = $sSrcId]/node()"/>168 </xsl:element>169 </xsl:template>170 369 171 370 <!-- … … 180 379 </xsl:template> 181 380 381 <!-- 382 Debug/Diagnostics: Return the path to the specified node (by default the current). 383 --> 384 <xsl:template name="get-node-path"> 385 <xsl:param name="Node" select="."/> 386 <xsl:for-each select="$Node"> 387 <xsl:for-each select="ancestor-or-self::node()"> 388 <xsl:choose> 389 <xsl:when test="name(.) = ''"> 390 <xsl:text>text()</xsl:text> 391 </xsl:when> 392 <xsl:otherwise> 393 <xsl:value-of select="concat('/', name(.))"/> 394 <xsl:choose> 395 <xsl:when test="@id"> 396 <xsl:text>[@id=</xsl:text> 397 <xsl:value-of select="@id"/> 398 <xsl:text>]</xsl:text> 399 </xsl:when> 400 <xsl:when test="position() > 1"> 401 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text> 402 </xsl:when> 403 </xsl:choose> 404 </xsl:otherwise> 405 </xsl:choose> 406 </xsl:for-each> 407 </xsl:for-each> 408 </xsl:template> 409 410 <!-- 411 Debug/Diagnostics: Return error message prefix. 412 --> 413 <xsl:template name="error-prefix"> 414 <xsl:param name="Node" select="."/> 415 <xsl:text>error: </xsl:text> 416 <xsl:call-template name="get-node-path"> 417 <xsl:with-param name="Node" select="$Node"/> 418 </xsl:call-template> 419 <xsl:text>: </xsl:text> 420 </xsl:template> 421 182 422 </xsl:stylesheet> 183 423
Note:
See TracChangeset
for help on using the changeset viewer.

