hgbook
changeset 557:23dc79421e06
Add XSL stylesheets
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon Feb 09 23:04:31 2009 -0800 (2009-02-09) |
parents | dbb4c40e2609 |
children | 8631da51309b |
files | xsl/all-ids.xsl xsl/base-html-stylesheet.xsl xsl/chunk-stylesheet.xsl xsl/dtd-profile.xsl |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xsl/all-ids.xsl Mon Feb 09 23:04:31 2009 -0800 1.3 @@ -0,0 +1,40 @@ 1.4 +<?xml version="1.0" encoding="utf-8"?> 1.5 + 1.6 +<!-- Prepare an ASCII dump file of all IDs, and the pages in which 1.7 + they live, for loading into a database. Assumes one-level chunked 1.8 + HTML output, with each chunk containing either a chapter or 1.9 + sect1. --> 1.10 + 1.11 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 1.12 + version="1.0"> 1.13 + 1.14 + <xsl:output method="text"/> 1.15 + <xsl:strip-space elements="title"/> 1.16 + 1.17 + <xsl:template match="/"> 1.18 + <xsl:for-each select="//preface|//chapter|//appendix|//bibliography|//sect1"> 1.19 + <xsl:variable name="id"> 1.20 + <xsl:choose> 1.21 + <xsl:when test="local-name(.)='sect1'"> 1.22 + <xsl:value-of select="../@id"/> 1.23 + </xsl:when> 1.24 + <xsl:otherwise> 1.25 + <xsl:value-of select="@id"/> 1.26 + </xsl:otherwise> 1.27 + </xsl:choose> 1.28 + </xsl:variable> 1.29 + <xsl:variable name="sectitle"> 1.30 + <xsl:value-of select="normalize-space(./title)"/> 1.31 + </xsl:variable> 1.32 + <xsl:for-each select=".//para[@id]|.//programlisting[@id]|.//screen[@id]"> 1.33 + <xsl:value-of select="@id"/> 1.34 + <xsl:text>|</xsl:text> 1.35 + <xsl:copy-of select="$id"/> 1.36 + <xsl:text>|</xsl:text> 1.37 + <xsl:copy-of select="$sectitle"/> 1.38 + <xsl:text>
</xsl:text> 1.39 + </xsl:for-each> 1.40 + </xsl:for-each> 1.41 + </xsl:template> 1.42 + 1.43 +</xsl:stylesheet>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/xsl/base-html-stylesheet.xsl Mon Feb 09 23:04:31 2009 -0800 2.3 @@ -0,0 +1,120 @@ 2.4 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> 2.5 + 2.6 + <xsl:param name="html.stylesheet">/support/styles.css</xsl:param> 2.7 + <xsl:param name="toc.section.depth">3</xsl:param> 2.8 + <xsl:param name="annotate.toc">0</xsl:param> 2.9 + 2.10 + <xsl:param name="generate.id.attributes" select="1"></xsl:param> 2.11 + <xsl:param name="header.rule" select="0"></xsl:param> 2.12 + <xsl:param name="footer.rule" select="0"></xsl:param> 2.13 + <xsl:param name="html.cleanup" select="1"></xsl:param> 2.14 + <xsl:param name="admon.style"><xsl:text></xsl:text></xsl:param> 2.15 + <xsl:param name="admon.graphics" select="1"></xsl:param> 2.16 + <xsl:param name="admon.graphics.path">/support/figs/</xsl:param> 2.17 + 2.18 + <xsl:template match="sect1" mode="toc"> 2.19 + <xsl:param name="toc-context" select="."/> 2.20 + <xsl:call-template name="subtoc"> 2.21 + <xsl:with-param name="toc-context" select="$toc-context"/> 2.22 + <xsl:with-param name="nodes" 2.23 + select="sect2|refentry|bridgehead[$bridgehead.in.toc != 0]"/> 2.24 + </xsl:call-template> 2.25 + </xsl:template> 2.26 + 2.27 + <xsl:template match="sect2" mode="toc"> 2.28 + <xsl:param name="toc-context" select="."/> 2.29 + 2.30 + <xsl:call-template name="subtoc"> 2.31 + <xsl:with-param name="toc-context" select="$toc-context"/> 2.32 + <xsl:with-param name="nodes" 2.33 + select="sect3|refentry|bridgehead[$bridgehead.in.toc != 0]"/> 2.34 + </xsl:call-template> 2.35 + </xsl:template> 2.36 + 2.37 + <!-- Add id attributes to <p> tags. This is mostly a copy of the 2.38 + base XSL. --> 2.39 + <xsl:template name="paragraph"> 2.40 + <xsl:param name="class" select="''"/> 2.41 + <xsl:param name="content"/> 2.42 + 2.43 + <xsl:variable name="p"> 2.44 + <p> 2.45 + <xsl:call-template name="dir"/> 2.46 + <xsl:if test="$class != ''"> 2.47 + <xsl:apply-templates select="." mode="class.attribute"> 2.48 + <xsl:with-param name="class" select="$class"/> 2.49 + </xsl:apply-templates> 2.50 + </xsl:if> 2.51 + <!-- Here we go. --> 2.52 + <xsl:if test="$generate.id.attributes != 0"> 2.53 + <xsl:attribute name="id"> 2.54 + <xsl:call-template name="object.id"/> 2.55 + </xsl:attribute> 2.56 + </xsl:if> 2.57 + <xsl:copy-of select="$content"/> 2.58 + </p> 2.59 + </xsl:variable> 2.60 + 2.61 + <xsl:choose> 2.62 + <xsl:when test="$html.cleanup != 0"> 2.63 + <xsl:call-template name="unwrap.p"> 2.64 + <xsl:with-param name="p" select="$p"/> 2.65 + </xsl:call-template> 2.66 + </xsl:when> 2.67 + <xsl:otherwise> 2.68 + <xsl:copy-of select="$p"/> 2.69 + </xsl:otherwise> 2.70 + </xsl:choose> 2.71 + </xsl:template> 2.72 + 2.73 + <!-- Add id attributes to <programlisting> and <screen> tags. Once 2.74 + again, this is mostly a copy of the base XSL, although rather 2.75 + trimmed down. --> 2.76 + <xsl:template match="programlisting|screen"> 2.77 + <xsl:param name="suppress-numbers" select="'0'"/> 2.78 + 2.79 + <xsl:call-template name="anchor"/> 2.80 + 2.81 + <pre> 2.82 + <!-- Here we go. --> 2.83 + <xsl:if test="$generate.id.attributes != 0"> 2.84 + <xsl:attribute name="id"> 2.85 + <xsl:call-template name="object.id"/> 2.86 + </xsl:attribute> 2.87 + </xsl:if> 2.88 + 2.89 + <xsl:apply-templates select="." mode="class.attribute"/> 2.90 + <xsl:call-template name="apply-highlighting"/> 2.91 + </pre> 2.92 + </xsl:template> 2.93 + 2.94 + <!-- The default stylesheet generates a little TOC at the beginning 2.95 + of each qandaset. Uh, no thanks. --> 2.96 + <xsl:template name="process.qanda.toc"/> 2.97 + 2.98 + <xsl:template name="user.header.navigation"> 2.99 + <div class="navheader"><h2 class="booktitle"><a href="/">Mercurial: The Definitive Guide</a> <span class="authors">by Bryan O'Sullivan</span></h2></div> 2.100 + </xsl:template> 2.101 + 2.102 + <xsl:template name="user.head.content"> 2.103 + <link rel="alternate" type="application/atom+xml" title="Comments" 2.104 + href="/feeds/comments/"/> 2.105 + <link rel="shortcut icon" type="image/png" href="/support/figs/favicon.png"/> 2.106 + <script type="text/javascript" src="/support/jquery-min.js"></script> 2.107 + <script type="text/javascript" src="/support/form.js"></script> 2.108 + <script type="text/javascript" src="/support/hsbook.js"></script> 2.109 + </xsl:template> 2.110 + 2.111 + <xsl:template name="user.footer.content"> 2.112 + <div class="rwhfooter"> 2.113 + <p><img src="/support/figs/rss.png"/> Want to stay up to date? Subscribe to the comment feed for <a id="chapterfeed" class="feed" href="/feeds/comments/">this chapter</a>, or the <a class="feed" href="/feeds/comments/">entire book</a>.</p> 2.114 + <p>Copyright 2009, Bryan O'Sullivan. 2.115 + Icons by <a href="mailto:mattahan@gmail.com">Paul Davey</a> aka <a href="http://mattahan.deviantart.com/">Mattahan</a>.</p> 2.116 + </div> 2.117 + </xsl:template> 2.118 + 2.119 + <xsl:template name="user.footer.navigation"> 2.120 + <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> 2.121 + <script type="text/javascript">_uacct = "UA-1805907-3"; urchinTracker();</script> 2.122 + </xsl:template> 2.123 +</xsl:stylesheet>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/xsl/chunk-stylesheet.xsl Mon Feb 09 23:04:31 2009 -0800 3.3 @@ -0,0 +1,17 @@ 3.4 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> 3.5 + 3.6 + <xsl:import href="system-xsl/html/chunk.xsl"/> 3.7 + <xsl:include href="base-html-stylesheet.xsl"/> 3.8 + 3.9 + <!-- PARAMETER REFERENCE: --> 3.10 + <!-- http://docbook.sourceforge.net/release/xsl/current/doc/html/ --> 3.11 + 3.12 + <!-- Uncomment this to enable auto-numbering of sections --> 3.13 + <!-- xsl:param name="section.autolabel" select="1" / --> 3.14 + <xsl:param name="chunker.output.encoding">UTF-8</xsl:param> 3.15 + <xsl:param name="use.id.as.filename" select="1"/> 3.16 + <xsl:param name="chunk.first.sections" select="0"/> 3.17 + <xsl:param name="chunk.section.depth" select="0"/> 3.18 + <xsl:param name="chunk.quietly" select="0"/> 3.19 + 3.20 +</xsl:stylesheet>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/xsl/dtd-profile.xsl Mon Feb 09 23:04:31 2009 -0800 4.3 @@ -0,0 +1,15 @@ 4.4 +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> 4.5 + <xsl:import href="system-xsl/profiling/profile.xsl"></xsl:import> 4.6 + 4.7 + <!-- For some reason, xsltproc omits the DTD from the file it 4.8 + outputs. Add a sensible one back in, because otherwise xmllint 4.9 + won't validate profiled documents. --> 4.10 + 4.11 + <xsl:template match="/"> 4.12 + <xsl:text disable-output-escaping="yes"><![CDATA[ 4.13 +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" 4.14 + "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"> 4.15 + ]]></xsl:text> 4.16 + <xsl:apply-templates select="." mode="profile"/> 4.17 + </xsl:template> 4.18 +</xsl:stylesheet>