Attachment 'xhtml.xsl'

Download

   1 <?xml version="1.0"?>
   2 <xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   3                 xmlns:str="http://exslt.org/strings" version="1.1">
   4   <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
   5 
   6   <xsl:template name="sectionid">
   7     <xsl:param name="title"/>
   8     <xsl:value-of select="str:replace($title, ' ', '_')"/>
   9   </xsl:template>
  10 
  11   <xsl:template name="linkto">
  12     <xsl:param name="page"/>
  13     <xsl:param name="subpage"/>
  14     <xsl:param name="title"/>
  15 
  16     <xsl:variable name="pageid">
  17       <xsl:call-template name="sectionid">
  18         <xsl:with-param name="title" select="$page"/>
  19       </xsl:call-template>
  20     </xsl:variable>
  21     <xsl:variable name="subpageid">
  22       <xsl:call-template name="sectionid">
  23         <xsl:with-param name="title" select="$subpage"/>
  24       </xsl:call-template>
  25     </xsl:variable>
  26     <a href="{$pageid}.html#{$subpageid}"><xsl:value-of select="$title"/></a>
  27   </xsl:template>
  28 
  29   <xsl:template match="/">
  30     <xsl:apply-templates select="article"/>
  31   </xsl:template>
  32 
  33   <xsl:template match="article">
  34     <html><xsl:apply-templates select="articleinfo|section"/></html>
  35   </xsl:template>
  36 
  37   <xsl:template match="articleinfo">
  38     <head>
  39       <xsl:apply-templates select="title"/>
  40       <link rel="stylesheet" type="text/css" href="default.css"/>
  41     </head>
  42   </xsl:template>
  43 
  44   <xsl:template match="article/section/title">
  45     <div class="header">
  46       <a href="index.html"><xsl:value-of select="."/></a>
  47     </div>
  48     <h1><xsl:value-of select="."/></h1>
  49   </xsl:template>
  50 
  51   <xsl:template match="articleinfo/title">
  52     <title><xsl:value-of select="/article/section/title"/></title>
  53   </xsl:template>
  54 
  55   <xsl:template match="article/section">
  56     <body>
  57       <xsl:apply-templates select="title"/>
  58       <ul class="toc">
  59         <xsl:for-each select="section">
  60           <li>
  61             <xsl:call-template name="linkto">
  62               <xsl:with-param name="page" select="title"/>
  63               <xsl:with-param name="title" select="title"/>
  64             </xsl:call-template>
  65             <xsl:if test="count(section) > 0">
  66               <ul>
  67                 <xsl:for-each select="section">
  68                   <li>
  69                     <xsl:call-template name="linkto">
  70                       <xsl:with-param name="page" select="../title"/>
  71                       <xsl:with-param name="subpage" select="title"/>
  72                       <xsl:with-param name="title" select="title"/>
  73                     </xsl:call-template>
  74                   </li>
  75                 </xsl:for-each>
  76               </ul>
  77             </xsl:if>
  78           </li>
  79         </xsl:for-each>
  80       </ul>
  81       <xsl:apply-templates select="section"/>
  82     </body>
  83   </xsl:template>
  84 
  85   <xsl:template match="article/section/section">
  86     <xsl:variable name="id">
  87       <xsl:call-template name="sectionid">
  88         <xsl:with-param name="title" select="title"/>
  89       </xsl:call-template>
  90     </xsl:variable>
  91     <xsl:document href="{$id}.html" method="xml" indent="yes" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN">
  92       <html>
  93         <head>
  94           <title><xsl:value-of select="title/text()"/> - <xsl:value-of select="/article/section/title"/></title>
  95           <link rel="stylesheet" type="text/css" href="default.css"/>
  96         </head>
  97         <body>
  98           <div class="header">
  99             <a href="index.html"><xsl:value-of select="/article/section/title"/></a>
 100           </div>
 101           <xsl:apply-templates select="title"/>
 102           <xsl:if test="count(section) > 0">
 103             <ul class="page_toc">
 104               <xsl:for-each select="section">
 105                 <li>
 106                   <xsl:call-template name="linkto">
 107                     <xsl:with-param name="page" select="../title"/>
 108                     <xsl:with-param name="subpage" select="title"/>
 109                     <xsl:with-param name="title" select="title"/>
 110                   </xsl:call-template>
 111                 </li>
 112               </xsl:for-each>
 113             </ul>
 114           </xsl:if>
 115           <xsl:apply-templates select="para|section|programlisting|screen|itemizedlist"/>
 116         </body>
 117       </html>
 118     </xsl:document>
 119   </xsl:template>
 120 
 121   <xsl:template match="article/section/section/title">
 122     <h2><xsl:value-of select="."/></h2>
 123   </xsl:template>
 124 
 125   <xsl:template match="article/section/section/section">
 126     <xsl:apply-templates select="para|section|programlisting|screen|itemizedlist|title|informaltable"/>
 127   </xsl:template>
 128 
 129   <xsl:template match="article/section/section/section/title">
 130     <xsl:variable name="id">
 131       <xsl:call-template name="sectionid">
 132         <xsl:with-param name="title" select="."/>
 133       </xsl:call-template>
 134     </xsl:variable>
 135     <h3><xsl:value-of select="."/><a name="{$id}">&#160;</a></h3>
 136   </xsl:template>
 137 
 138   <xsl:template match="article/section/section/section/section">
 139     <xsl:apply-templates select="para|section|programlisting|screen|itemizedlist|title|informaltable"/>
 140   </xsl:template>
 141 
 142   <xsl:template match="article/section/section/section/section/title">
 143     <xsl:variable name="id">
 144       <xsl:call-template name="sectionid">
 145         <xsl:with-param name="title" select="."/>
 146       </xsl:call-template>
 147     </xsl:variable>
 148     <h4><xsl:value-of select="."/><a name="{$id}">&#160;</a></h4>
 149   </xsl:template>
 150 
 151   <xsl:template match="para">
 152     <p><xsl:apply-templates select="text()|code|ulink|emphasis"/></p>
 153   </xsl:template>
 154 
 155   <xsl:template match="emphasis">
 156     <strong><xsl:apply-templates select="text()"/></strong>
 157   </xsl:template>
 158 
 159   <xsl:template match="ulink">
 160     <xsl:if test="starts-with(@url,'http://live.gnome.org/Vala/Manual/')">
 161       <xsl:variable name="pageid">
 162         <xsl:call-template name="sectionid">
 163           <xsl:with-param name="title" select="str:decode-uri(str:tokenize(substring-after(@url, 'http://live.gnome.org/Vala/Manual/'),'#')[1])"/>
 164         </xsl:call-template>
 165       </xsl:variable>
 166       <a href="{$pageid}.html#{str:tokenize(substring-after(@url, 'http://live.gnome.org/Vala/Manual/'),'#')[2]}"><xsl:value-of select="."/></a>
 167     </xsl:if>
 168     <xsl:if test="not(starts-with(@url,'http://live.gnome.org/Vala/Manual/'))">
 169       <a href="{@url}"><xsl:value-of select="."/></a>
 170     </xsl:if>
 171   </xsl:template>
 172 
 173 
 174   <xsl:template match="para/code">
 175     <xsl:if test="contains (text(), '&#x0a;')">
 176       <pre><xsl:value-of select="text()"/></pre>
 177     </xsl:if>
 178     <xsl:if test="not (contains (text(), '&#x0a;'))">
 179       <code><xsl:value-of select="text()"/></code>
 180     </xsl:if>
 181   </xsl:template>
 182 
 183   <xsl:template match="screen">
 184     <pre><xsl:value-of select="text()"/></pre>
 185   </xsl:template>
 186 
 187   <xsl:template match="programlisting">
 188     <pre><xsl:apply-templates select="text()|type|methodname|token|phrase"/></pre>
 189   </xsl:template>
 190 
 191   <xsl:template match="type">
 192     <span class="type"><xsl:value-of select="."/></span>
 193   </xsl:template>
 194 
 195   <xsl:template match="token">
 196     <span class="token"><xsl:value-of select="."/></span>
 197   </xsl:template>
 198 
 199   <xsl:template match="methodname">
 200     <span class="methodname"><xsl:value-of select="."/></span>
 201   </xsl:template>
 202 
 203   <xsl:template match="phrase">
 204     <span class="phrase"><xsl:value-of select="."/></span>
 205   </xsl:template>
 206 
 207   <!-- lists -->
 208 
 209   <xsl:template match="itemizedlist[listitem[not(@override)]]">
 210     <ul><xsl:apply-templates select="listitem"/></ul>
 211   </xsl:template>
 212 
 213   <xsl:template match="listitem[not(@override)]">
 214     <li><xsl:apply-templates select="para"/></li>
 215   </xsl:template>
 216 
 217   <xsl:template match="itemizedlist[listitem[@override='none']]">
 218     <blockquote><xsl:apply-templates select="listitem"/></blockquote>
 219   </xsl:template>
 220 
 221   <xsl:template match="listitem[@override='none']/itemizedlist"><xsl:apply-templates select="listitem"/><xsl:text>
 222 </xsl:text></xsl:template>
 223 
 224   <xsl:template match="listitem[@override='none']">
 225     <xsl:apply-templates select="para|itemizedlist"/>
 226   </xsl:template> 
 227 
 228   <xsl:template match="listitem[@override='none']/para"><xsl:apply-templates select="text()|emphasis"/><xsl:text>
 229 </xsl:text></xsl:template>
 230 
 231   <xsl:template match="listitem[@override='none']/para/text()">
 232     <xsl:if test="position()=1 and starts-with(.,' ')">
 233       <xsl:if test="normalize-space(.)!=''"><xsl:value-of select="substring-after(.,' ')"/></xsl:if>
 234     </xsl:if>
 235     <xsl:if test="position()!=1 or not(starts-with(.,' '))">
 236       <xsl:if test="normalize-space(.)!=''"><xsl:value-of select="."/></xsl:if>
 237     </xsl:if>
 238   </xsl:template>
 239 
 240   <xsl:template match="listitem[@override='none']/para/emphasis[@role='strong']"><span class="literal"><xsl:value-of select="."/></span></xsl:template>
 241 <xsl:template match="listitem[@override='none']/itemizedlist/listitem[@override='none']/para"><xsl:text>&#x09;</xsl:text><xsl:apply-templates select="text()|emphasis"/><xsl:text>
 242 </xsl:text></xsl:template>
 243 
 244   <!-- tables -->
 245   <xsl:template match="informaltable">
 246     <table>
 247       <xsl:apply-templates select="tgroup/tbody/row"/>
 248     </table>
 249   </xsl:template>
 250 
 251   <xsl:template match="row">
 252     <tr>
 253       <xsl:apply-templates select="entry"/>
 254     </tr>
 255   </xsl:template>
 256 
 257   <xsl:template match="entry">
 258     <td xsl:use-attribute-sets="entry-attrs">
 259       <xsl:apply-templates select="para"/>
 260     </td>
 261   </xsl:template>
 262 
 263   <xsl:attribute-set name="entry-attrs">
 264     <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
 265     <xsl:attribute name="colspan">
 266       <xsl:if test="@nameend"><xsl:value-of select="number(substring-after(@nameend, 'col_'))+1"/></xsl:if>
 267     </xsl:attribute>
 268   </xsl:attribute-set>
 269    
 270 </xsl:stylesheet>

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2021-02-25 10:01:26, 1.4 KB) [[attachment:default.css]]
  • [get | view] (2021-02-25 10:01:26, 0.8 KB) [[attachment:toc.xsl]]
  • [get | view] (2021-02-25 10:01:26, 9.6 KB) [[attachment:xhtml.xsl]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.