1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:d='http://docbook.org/ns/docbook'
xmlns:xlink='http://www.w3.org/1999/xlink'
xmlns:tcl='http://tclxml.sourceforge.net/doc'
xmlns:str='http://xsltsl.org/string'
extension-element-prefixes='str'
exclude-result-prefixes="d xlink tcl">
<xsl:import href='xsltsl/stdlib.xsl'/>
<d:article>
<d:info>
<d:title>Text Stylesheet</d:title>
<d:copyright>
<d:year>2008</d:year>
<d:holder>Explain</d:holder>
</d:copyright>
</d:info>
<d:para>This stylesheet produces a text rendition of a DocBook document.</d:para>
</d:article>
<xsl:output method='text'/>
<xsl:strip-space elements='*'/>
<xsl:preserve-space elements='d:programlisting d:literallayout d:command'/>
<xsl:template match='d:article'>
<xsl:choose>
<xsl:when test='d:title'>
<xsl:apply-templates select='d:title'/>
</xsl:when>
<xsl:when test='d:info/d:title'>
<xsl:apply-templates select='d:info/d:title'/>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select='d:info/d:author'/>
<xsl:text>
</xsl:text>
<xsl:apply-templates select='*[not(self::d:info|self::d:title)]'/>
</xsl:template>
<xsl:template match='d:article/d:title|d:article/d:info/d:title'>
<xsl:text>
</xsl:text>
<xsl:apply-templates/>
<xsl:text>
</xsl:text>
<xsl:if test='following-sibling::d:subtitle'>
<xsl:text> </xsl:text>
<xsl:apply-templates select='following-sibling::d:subtitle'/>
<xsl:if test='following-sibling::d:revhistory'>
<xsl:text> Version </xsl:text>
<xsl:apply-templates select='following-sibling::d:revhistory/d:revision[1]/d:revnumber'/>
</xsl:if>
</xsl:if>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match='d:author'>
<xsl:apply-templates select='d:firstname'/>
<xsl:text> </xsl:text>
<xsl:apply-templates select='d:surname'/>
<xsl:if test='d:affiliation'>
<xsl:text>, </xsl:text>
<xsl:apply-templates select='d:affiliation/d:orgname'/>
</xsl:if>
</xsl:template>
<xsl:template match='d:para'>
<xsl:param name='indent' select='0'/>
<xsl:param name='linelen' select='80'/>
<xsl:call-template name='str:justify'>
<xsl:with-param name='text'>
<xsl:apply-templates/>
</xsl:with-param>
<xsl:with-param name='indent' select='$indent'/>
<xsl:with-param name='max' select='$linelen'/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match='d:note'>
<xsl:call-template name='str:justify'>
<xsl:with-param name='text'>
<xsl:apply-templates/>
</xsl:with-param>
<xsl:with-param name='indent' select='4'/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match='d:section'>
<xsl:text>
</xsl:text>
<xsl:apply-templates select='d:info/d:title'/>
<xsl:if test='d:info/d:subtitle'>
<xsl:text> (</xsl:text>
<xsl:apply-templates select='d:info/d:subtitle'/>
<xsl:text>)</xsl:text>
</xsl:if>
<xsl:text>
</xsl:text>
<xsl:variable name='titlelen'>
<xsl:choose>
<xsl:when test='d:subtitle'>
<xsl:value-of select='string-length(d:info/d:title) + 3 + string-length(d:info/d:subtitle)'/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='string-length(d:info/d:title)'/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name='str:generate-string'>
<xsl:with-param name='count' select='$titlelen'/>
<xsl:with-param name='text'>
<xsl:choose>
<xsl:when test='parent::d:section'>-</xsl:when>
<xsl:otherwise>=</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<xsl:text>
</xsl:text>
<xsl:apply-templates select='*[not(self::d:info)]'/>
</xsl:template>
<xsl:template match='d:itemizedlist'>
<xsl:apply-templates select='d:listitem'/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match='d:itemizedlist/d:listitem'>
<xsl:call-template name='str:generate-string'>
<xsl:with-param name='text' select='" "'/>
<xsl:with-param name='count' select='count(ancestor::d:itemizedlist|ancestor::d:variablelist) * 4'/>
</xsl:call-template>
<xsl:text>* </xsl:text>
<xsl:apply-templates select='*'>
<xsl:with-param name='indent' select='count(ancestor::d:itemizedlist|ancestor::d:variablelist) * 4'/>
<xsl:with-param name='linelen' select='80 - count(ancestor::d:itemizedlist|ancestor::d:variablelist) * 4'/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match='d:variablelist'>
<xsl:apply-templates select='d:varlistentry'/>
</xsl:template>
<xsl:template match='d:varlistentry'>
<xsl:call-template name='str:generate-string'>
<xsl:with-param name='text' select='" "'/>
<xsl:with-param name='count' select='(count(ancestor::d:variablelist|ancestor::d:itemizedlist) - 1) * 4'/>
</xsl:call-template>
<xsl:apply-templates select='d:term'/>
<xsl:apply-templates select='d:listitem'/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match='d:varlistentry/d:term'>
<xsl:apply-templates/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match='d:varlistentry/d:listitem'>
<xsl:apply-templates select='*'>
<xsl:with-param name='indent' select='count(ancestor::d:variablelist|ancestor::d:itemizedlist) * 4'/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match='d:programlisting|d:literallayout'>
<xsl:call-template name='indent'>
<xsl:with-param name='text' select='.'/>
<xsl:with-param name='indent' select='(count(ancestor::d:itemizedlist|ancestor::d:variablelist) + 1) * 4'/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name='indent'>
<xsl:param name='text'/>
<xsl:param name='indent' select='4'/>
<xsl:choose>
<xsl:when test='not($text)'/>
<xsl:when test='contains($text, "
")'>
<xsl:call-template name='str:generate-string'>
<xsl:with-param name='text' select='" "'/>
<xsl:with-param name='count' select='$indent'/>
</xsl:call-template>
<xsl:value-of select='substring-before($text, "
")'/>
<xsl:text>
</xsl:text>
<xsl:call-template name='indent'>
<xsl:with-param name='text' select='substring-after($text, "
")'/>
<xsl:with-param name='indent' select='$indent'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name='str:generate-string'>
<xsl:with-param name='text' select='" "'/>
<xsl:with-param name='count' select='$indent'/>
</xsl:call-template>
<xsl:value-of select='$text'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match='d:link'>
<xsl:apply-templates/>
<xsl:text> [</xsl:text>
<xsl:value-of select='@xlink:href'/>
<xsl:text>]</xsl:text>
</xsl:template>
</xsl:stylesheet>
|