-
Notifications
You must be signed in to change notification settings - Fork 2
/
faq.xsl
280 lines (222 loc) · 8.39 KB
/
faq.xsl
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet>
<!--*
* Create the FAQ HTML pages from one XML source file
*-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:extfuncs="http://hea-www.harvard.edu/~dburke/xsl/extfuncs"
extension-element-prefixes="extfuncs">
<!--* Change this if the filename changes *-->
<xsl:variable name="hack-import-faq" select="extfuncs:register-import-dependency('faq.xsl')"/>
<xsl:output method="text"/>
<!--* we place this here to see if it works (was in header.xsl and wasn't working
* - and it seems to
*-->
<!--* a template to output a new line (useful after a comment) *-->
<xsl:template name="newline">
<xsl:text>
</xsl:text>
</xsl:template>
<!--* load in the set of "global" parameters *-->
<xsl:include href="globalparams.xsl"/>
<!--* include the stylesheets AFTER defining the variables *-->
<xsl:include href="helper.xsl"/>
<xsl:include href="links.xsl"/>
<xsl:include href="myhtml.xsl"/>
<!--*
* top level: create
* index.html
*
*-->
<xsl:template match="/">
<!--* check the params are okay *-->
<xsl:call-template name="is-site-valid"/>
<xsl:call-template name="check-param-ends-in-a-slash">
<xsl:with-param name="pname" select="'install'"/>
<xsl:with-param name="pvalue" select="$install"/>
</xsl:call-template>
<xsl:call-template name="check-param-ends-in-a-slash">
<xsl:with-param name="pname" select="'canonicalbase'"/>
<xsl:with-param name="pvalue" select="$canonicalbase"/>
</xsl:call-template>
<!--* check there's a navbar element *-->
<xsl:if test="boolean(faq/info/navbar) = false()">
<xsl:message terminate="yes">
Error: the info block does not contain a navbar element.
</xsl:message>
</xsl:if>
<!--*
* If I take out the mode attributes here and in the
* xsl:template nodes below then the output is not correct
* since only some of the templates seem to get executed.
* I do not understand why (could it be a libxml/libxslt
* bug?)
*-->
<xsl:apply-templates select="faq" mode="why-this-mode"/>
<xsl:apply-templates select="//faqentry"/>
</xsl:template> <!--* match=/ *-->
<!--*
* create: index.html
*-->
<xsl:template match="faq" mode="why-this-mode">
<xsl:variable name="filename"><xsl:value-of select="$install"/>index.html</xsl:variable>
<!--* output filename to stdout *-->
<xsl:value-of select="$filename"/><xsl:call-template name="newline"/>
<!--* create document *-->
<xsl:document href="{$filename}" method="html" media-type="text/html"
doctype-system="about:legacy-compat"
version="5.0">
<!--* we start processing the XML file here *-->
<html lang="en-US">
<!--* make the HTML head node *-->
<xsl:call-template name="add-htmlhead-standard"/>
<xsl:variable name="contents">
<!--* add the intro text *-->
<xsl:apply-templates select="intro"/>
<!--* create the list of FAQ's *-->
<xsl:apply-templates select="faqlist" mode="toc"/>
</xsl:variable>
<xsl:variable name="navbar">
<xsl:call-template name="add-navbar">
<xsl:with-param name="name" select="info/navbar"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="add-body-withnavbar">
<xsl:with-param name="contents" select="$contents"/>
<xsl:with-param name="navbar" select="$navbar"/>
<!-- uses default //info/breadcrumbs -->
<xsl:with-param name="location" select="$filename"/>
</xsl:call-template>
</html>
</xsl:document>
</xsl:template> <!--* match=faq *-->
<!--*
* create: individual faq page
*-->
<xsl:template match="faqentry">
<xsl:variable name="filename"><xsl:value-of select="$install"/><xsl:value-of select="@id"/>.html</xsl:variable>
<!--* output filename to stdout *-->
<xsl:value-of select="$filename"/><xsl:call-template name="newline"/>
<!--* create document *-->
<xsl:document href="{$filename}" method="html" media-type="text/html"
doctype-system="about:legacy-compat"
version="5.0">
<html lang="en-US">
<xsl:call-template name="add-htmlhead">
<!-- We used to just have this as FAQ Entry rather than the actual
title, in case it was too long, but have changed this
-->
<xsl:with-param name="title">
<xsl:value-of select="concat('FAQ: ', normalize-space(title))"/><xsl:if test="$texttitlepostfix!=''"><xsl:value-of select="concat(' - ',$texttitlepostfix)"/></xsl:if>
</xsl:with-param>
<xsl:with-param name="page" select="concat(@id, '.html')"/>
<!-- need to ensure any CSS in the main page gets set to the
sub-pages; should we process the contents? -->
<xsl:with-param name="css"
select="//info/css"/>
</xsl:call-template>
<xsl:variable name="contents">
<div class="mainbar">
<div>
<h1 class="pagetitle"><xsl:apply-templates select="title"/><xsl:call-template name="add-new-or-updated-info"/></h1>
<xsl:apply-templates select="errmsg"/>
</div>
<hr/>
<xsl:apply-templates select="text"/>
<hr/>
</div>
</xsl:variable>
<xsl:call-template name="add-body-nonavbar">
<xsl:with-param name="contents" select="$contents"/>
<!-- uses default //info/breadcrumbs -->
<xsl:with-param name="location" select="$filename"/>
</xsl:call-template>
</html>
</xsl:document>
</xsl:template> <!--* match=faqentry *-->
<!--*
* Create the list of faq questions
*
*
*-->
<xsl:template match="faqlist" mode="toc">
<!--* create the list of topics *-->
<div class="navlinkbar qlinkbar">
<xsl:for-each select="faqtopic">
<xsl:if test="position() != 1"> | </xsl:if>
<a href="#{@id}"><xsl:value-of select="name"/></a>
</xsl:for-each>
</div>
<hr/>
<br/>
<!--* and now the list of entries *-->
<xsl:for-each select="faqtopic">
<!--* if not the first topic then add a hr *-->
<xsl:if test="position() != 1">
<hr class="midsep"/>
</xsl:if>
<!--* the header *-->
<h2 id="{@id}"><xsl:value-of select="name"/></h2>
<!--* loop through the sections *-->
<xsl:for-each select="faqsection">
<h3><xsl:if test="boolean(name[@id])"><xsl:attribute name="id">
<xsl:value-of select="name/@id"/>
</xsl:attribute></xsl:if><xsl:apply-templates select="name"/></h3>
<!--* list through each entry *-->
<ol type="1">
<xsl:for-each select="faqentry">
<li><a href="{@id}.html"><xsl:apply-templates select="title"/></a>
<xsl:call-template name="add-new-or-updated-info">
<xsl:with-param name="with-date" select="1"/>
</xsl:call-template>
<!--* do we need to add an error message? *-->
<xsl:apply-templates select="errmsg"/>
</li>
</xsl:for-each> <!--* faqentry *-->
</ol>
</xsl:for-each> <!--* faqsection *-->
</xsl:for-each> <!--* faqtopic *-->
</xsl:template> <!--* match=faqlist mode=toc *-->
<!--* remove the 'whatever' tag and process the contents *-->
<xsl:template match="intro|name|title|text">
<xsl:apply-templates/>
</xsl:template>
<!--*
* handle the errmsg tag
*
* - perhaps we should place the pre block within a
* div class="errmsg" block?
*
*-->
<xsl:template match="errmsg">
<xsl:call-template name="add-highlight-pre">
<xsl:with-param name="contents"><xsl:apply-templates/></xsl:with-param>
</xsl:call-template>
</xsl:template>
<!--*
* adds a new or updated icon if the type attribute exists and
* equals "new" or "updated" (we assume the curent context node
* to be faqentry).
*
* Also uses the day/month/year attributes
*
* Note:
*
*-->
<xsl:template name="add-new-or-updated-info">
<xsl:param name="with-date" select="0"/>
<xsl:choose>
<xsl:when test="@type = 'new'">
<xsl:call-template name="add-nbsp"/>
<xsl:call-template name="add-new-image"/>
<xsl:if test="boolean($with-date) and boolean(@day)"><xsl:call-template name="add-date"/></xsl:if>
</xsl:when>
<xsl:when test="@type = 'updated'">
<xsl:call-template name="add-nbsp"/>
<xsl:call-template name="add-updated-image"/>
<xsl:if test="boolean($with-date) and boolean(@day)"><xsl:call-template name="add-date"/></xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template> <!--* name=add-new-or-updated-info *-->
</xsl:stylesheet>