root/trunk/spec/preprocess_html.xsl

Revision 7, 4.9 KB (checked in by oren, 8 months ago)

April 06, 2008 draft.

Implemented by YamlReference? 0.9.

Contains new productions, new examples, all the changes collected throughout
the last 3 years, and of course JSON compatibility.

Line 
1<?xml version="1.0"?> 
2
3<!--
4 - Pre-process the spec before handing it over to standard DocBook. This allows
5 - using convenient shorthands that DocBook does not provide. Currently these
6 - shorthands are:
7 -
8 - <defterm>term</defterm> is converted to an <indexterm>, using "term" as
9 - the primary, with "preferred" significance. This is used to create a short
10 - index of "important terms" as an appendix.
11 -
12 - <refterm>term</refterm> is converted to an <indexterm>, using "term" as
13 - the primary, with "normal" significance. This is used to add list of
14 - usage points to each "important terms" in the appendix.
15-->
16
17<xsl:stylesheet
18    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
19    version="1.0"> 
20
21  <!-- Generate the DOCBOOk DTD decleration. Can't copy it! -->
22  <xsl:output
23    method="xml" doctype-public="-//OASIS//DTD DocBook V4.2//EN"
24    doctype-system="http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" />
25
26  <!-- Convert uquote to userinput quote. -->
27  <xsl:template match="uquote"
28    ><quote
29      ><userinput
30        ><xsl:apply-templates select='*|text()'
31      /></userinput
32    ></quote
33  ></xsl:template>
34
35  <!-- Convert defterm to index entry definition. -->
36  <xsl:template match="defterm">
37    <indexterm significance="preferred">
38      <primary><xsl:value-of select='@primary'/></primary>
39      <xsl:if test="@secondary">
40        <secondary><xsl:value-of select='@secondary'/></secondary>
41      </xsl:if>
42      <xsl:if test="@tertiary">
43        <tertiary><xsl:value-of select='@tertiary'/></tertiary>
44      </xsl:if>
45    </indexterm>
46    <anchor>
47      <xsl:attribute name="id">
48        <xsl:value-of select='@primary'/>/<xsl:value-of select='@secondary'/>/<xsl:value-of select='@tertiary'/>
49      </xsl:attribute>
50    </anchor>
51    <firstterm
52      ><xsl:apply-templates select='*|text()'
53    /></firstterm>
54  </xsl:template>
55
56  <!-- Convert refterm to index entry definition. -->
57  <xsl:template match="refterm">
58    <indexterm significance="normal">
59      <primary><xsl:value-of select='@primary'/></primary>
60      <xsl:if test="@secondary">
61        <secondary><xsl:value-of select='@secondary'/></secondary>
62      </xsl:if>
63      <xsl:if test="@tertiary">
64        <tertiary><xsl:value-of select='@tertiary'/></tertiary>
65      </xsl:if>
66    </indexterm>
67    <link>
68      <xsl:attribute name="linkend">
69        <xsl:value-of select='@primary'/>/<xsl:value-of select='@secondary'/>/<xsl:value-of select='@tertiary'/>
70      </xsl:attribute>
71      <xsl:apply-templates select='*|text()'/>
72    </link>
73  </xsl:template>
74
75  <!-- Convert seeterm to index entry definition. -->
76  <xsl:template match="seeterm">
77    <indexterm>
78      <primary><xsl:value-of select='@primary'/></primary>
79      <secondary><xsl:value-of select='@secondary'/></secondary>
80      <tertiary><xsl:value-of select='@tertiary'/></tertiary>
81      <see><xsl:value-of select='@see' /></see>
82    </indexterm>
83  </xsl:template>
84
85  <!-- Convert seealso to index entry definition. -->
86  <xsl:template match="seealso">
87    <indexterm>
88      <primary><xsl:value-of select='@primary'/></primary>
89      <secondary><xsl:value-of select='@secondary'/></secondary>
90      <tertiary><xsl:value-of select='@tertiary'/></tertiary>
91      <seealso><xsl:value-of select='@see' /></seealso>
92    </indexterm>
93  </xsl:template>
94
95  <!-- Convert screen -->
96  <xsl:template match="screen">
97    <screen><database><xsl:apply-templates
98                        select='*|text()'/></database></screen>
99  </xsl:template>
100
101  <!-- Convert programlisting -->
102  <xsl:template match="programlisting">
103    <programlisting><database><xsl:apply-templates
104                                select='*|text()'/></database></programlisting>
105  </xsl:template>
106
107  <!-- Convert hl1 -->
108  <xsl:template match="hl1">
109    <filename>
110      <xsl:apply-templates select='*|text()'/>
111    </filename>
112  </xsl:template>
113
114  <!-- Convert hl2 -->
115  <xsl:template match="hl2">
116    <literal>
117      <xsl:apply-templates select='*|text()'/>
118    </literal>
119  </xsl:template>
120
121  <!-- Convert hl3 -->
122  <xsl:template match="hl3">
123    <property>
124      <xsl:apply-templates select='*|text()'/>
125    </property>
126  </xsl:template>
127
128  <!-- Convert hl4 -->
129  <xsl:template match="hl4">
130    <constant>
131      <xsl:apply-templates select='*|text()'/>
132    </constant>
133  </xsl:template>
134
135  <!-- Convert HL -->
136  <xsl:template match="HL">
137    <honorific>
138      <xsl:apply-templates select='*|text()'/>
139    </honorific>
140  </xsl:template>
141
142  <!-- Pass html only -->
143  <xsl:template match="html"
144    ><xsl:apply-templates select='*|text()'
145  /></xsl:template>
146
147  <!-- Pass keep-together -->
148  <xsl:template match="keep-together"
149    ><xsl:apply-templates select='*|text()'
150  /></xsl:template>
151
152  <!-- Slanted single quotes -->
153  <xsl:template match="q">&#8217;</xsl:template>
154
155  <!-- Copy everything else unchanged. -->
156  <xsl:template match='*|@*'>
157    <xsl:copy>
158      <xsl:apply-templates select='node()|@*'/>
159    </xsl:copy>
160  </xsl:template>
161
162</xsl:stylesheet> 
Note: See TracBrowser for help on using the browser.