/[volute]/trunk/projects/vocabularies/doc/structure.xslt
ViewVC logotype

Contents of /trunk/projects/vocabularies/doc/structure.xslt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 732 - (show annotations)
Tue Aug 19 10:05:16 2008 UTC (12 years, 6 months ago) by norman.x.gray
File size: 12145 byte(s)
Add comment documenting the structure of the input file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform"
3 version="1.0"
4 exclude-result-prefixes="h"
5 xmlns:h="http://www.w3.org/1999/xhtml"
6 xmlns="http://www.w3.org/1999/xhtml"
7 xmlns:dc="http://purl.org/dc/elements/1.1/"
8 xmlns:dcterms="http://purl.org/dc/terms/">
9
10 <x:output method="xml"
11 encoding="UTF-8"
12 version="1.0"/>
13
14 <!--
15 The following supports a mildly-enhanced version of XHTML. Most
16 notably, it supports sectioning via nested <div class='section'>
17 elements, with the section title being given by a
18 <p class='title'> child of the <div>. The <div> class can also
19 be 'section-nonum', with the obvious meaning, and the div can
20 have an 'id' attribute which allows cross-references to it.
21 Cross-references are supported by a <span class='xref'>id</span> element.
22
23 Appendices go in a <div class='appendices'>, and an abstract in
24 <div class='abstract'>
25
26 The <div>s can be collected into a ToC, at a location marked by
27 a <?toc?> PI.
28
29 Bibliography: entries can be marked with <span
30 class='cite'>ref</span>, and these can be collected into a .aux
31 file by running this stylesheet with the parameter 'target'
32 given as 'aux'. The location of the bibliography is marked by a
33 <?bibliography?> PI: this simply reads in a file
34 $document-id.bbl, the generation of which must be managed
35 externally to this script.
36
37 There's also a <span class='url'>url</span>, which formats the
38 URL appropriately, and a
39 <span class='rcsinfo'>$foo: bar $</span>, which extracts the
40 contents 'bar' from the string.
41
42 The output has extra properties added to support RDFa, using
43 information extracted from 'title' and 'abstract', and from
44 <meta name='DC.xxx'> and <meta name='rcsdate'> fields in the <head>
45 -->
46
47 <!-- We include support for RDFa in the following, via: the output doctype,
48 the 'profile' attribute in the head element, and the various 'property'
49 attributes in the text.
50 See <http://www.w3.org/TR/2008/WD-rdfa-syntax-20080221/#docconf>.
51 We also add a GRDDL transformation which independently specifies
52 the RDFa transformation. -->
53
54 <x:param name="target"/>
55
56 <x:param name="document-id">document-id</x:param>
57
58 <!-- default identity transformation -->
59 <x:template match="node()|@*">
60 <x:copy>
61 <x:apply-templates select="node()|@*"/>
62 </x:copy>
63 </x:template>
64
65 <!-- process root node -->
66 <x:template match="/">
67 <x:choose>
68 <x:when test="$target='aux'">
69 <x:apply-templates select="//processing-instruction('bibliography')"
70 mode="extract-aux"/>
71 </x:when>
72 <x:when test="$target">
73 <x:message terminate="yes">Unrecognised target <x:value-of select="$target"/>
74 </x:message>
75 </x:when>
76 <x:otherwise>
77 <x:apply-templates/>
78 </x:otherwise>
79 </x:choose>
80 </x:template>
81
82 <!-- Add the GRDDL transformation magic attribute to the HTML element -->
83 <x:template match="h:html" xmlns:grddl="http://www.w3.org/2003/g/data-view#">
84 <html grddl:transformation='http://ns.inria.fr/grddl/rdfa/2007/05/25/RDFa2RDFXML.xsl'>
85 <x:apply-templates/>
86 </html>
87 </x:template>
88
89 <x:template match="h:head">
90 <head profile='http://www.w3.org/1999/xhtml/vocab'>
91 <x:apply-templates select="@*"/>
92 <x:copy-of select="namespace::*[.='http://purl.org/dc/elements/1.1/']"/>
93 <x:choose>
94 <x:when test="h:link[@rel='stylesheet']">
95 <x:comment>Using stylesheet from source file</x:comment>
96 <x:apply-templates select="h:link[@rel='stylesheet']"/>
97 </x:when>
98 <x:otherwise>
99 <link rel="stylesheet" type="text/css" href="/style/base.css"/>
100 </x:otherwise>
101 </x:choose>
102 <x:apply-templates select="h:title|h:meta|h:style"/>
103 </head>
104 </x:template>
105
106
107 <x:template match="h:div[@class='section' or @class='section-nonum']">
108 <x:variable name='id'>
109 <x:call-template name='make-section-id'/>
110 </x:variable>
111 <x:variable name="level">
112 <x:choose>
113 <x:when test="ancestor::h:div[@class='section']/ancestor::h:div[@class='section']">h4</x:when>
114 <x:when test="ancestor::h:div[@class='section']">h3</x:when>
115 <x:otherwise>h2</x:otherwise>
116 </x:choose>
117 </x:variable>
118 <x:element name='{$level}'>
119 <a name='{$id}'><x:apply-templates select='.' mode='make-section-name'/></a>
120 </x:element>
121 <x:apply-templates/>
122 </x:template>
123 <!--
124 <x:template match="h:div[@class='section' or @class='section-nonum']">
125 <x:variable name="id">
126 <x:call-template name="make-section-id"/>
127 </x:variable>
128 <x:variable name="level">
129 <x:choose>
130 <x:when test="ancestor::h:div[@class='section']/ancestor::h:div[@class='section']">h4</x:when>
131 <x:when test="ancestor::h:div[@class='section']">h3</x:when>
132 <x:otherwise>h2</x:otherwise>
133 </x:choose>
134 </x:variable>
135 <x:element name="{$level}" namespace='http://www.w3.org/1999/xhtml'>
136 <x:if test="@id">
137 <x:attribute name='class'>hlink</x:attribute>
138 </x:if>
139 <x:apply-templates select="." mode="make-section-name"/>
140 <x:element name='a' namespace='http://www.w3.org/1999/xhtml'>
141 <x:attribute name='name'><x:value-of select='$id'/></x:attribute>
142 <x:if test="@id">
143 <x:attribute name='href'>#<x:value-of select='$id'/></x:attribute>
144 <x:text> [link here]</x:text>
145 </x:if>
146 </x:element>
147 </x:element>
148 <x:apply-templates/>
149 </x:template>
150 -->
151
152 <x:template match="h:p[@class='title']"/>
153
154 <x:template match="h:div[@class='appendices']">
155 <h2>Appendices</h2>
156 <x:apply-templates/>
157 </x:template>
158
159 <x:template match="h:div" mode="make-toc">
160 <x:variable name="id">
161 <x:call-template name="make-section-id"/>
162 </x:variable>
163 <li>
164 <a href='#{$id}'>
165 <x:apply-templates select='.' mode='make-section-name'/>
166 </a>
167 <x:if test="h:div[@class='section' or @class='section-nonum']">
168 <ul>
169 <x:apply-templates select="h:div[@class='section' or @class='section-nonum']" mode="make-toc"/>
170 </ul>
171 </x:if>
172 </li>
173 </x:template>
174
175 <x:template match="processing-instruction('toc')">
176 <div id='toc' class='toc'>
177 <ul>
178 <x:apply-templates select="//h:body/h:div[@class='section' or @class='section-nonum']|//h:body/h:div[@class='appendices']/h:div" mode="make-toc"/>
179 </ul>
180 </div>
181 </x:template>
182
183 <x:template name="make-section-id">
184 <x:choose>
185 <x:when test="@id">
186 <x:value-of select="@id"/>
187 </x:when>
188 <x:otherwise>
189 <x:value-of select="generate-id()"/>
190 </x:otherwise>
191 </x:choose>
192 </x:template>
193
194 <x:template match="h:div" mode="make-section-name">
195 <x:choose>
196 <x:when test="ancestor-or-self::h:div[@class='section-nonum']"/>
197 <x:when test="ancestor::h:div[@class='appendices']">
198 <x:number count="h:div[@class='section']" level="multiple" format="A.1."/>
199 <x:text> </x:text>
200 </x:when>
201 <x:otherwise>
202 <x:number count="h:div[@class='section']" level="multiple" format="1.1."/>
203 <x:text> </x:text>
204 </x:otherwise>
205 </x:choose>
206 <x:apply-templates select="h:p[@class='title']/text()"/>
207 </x:template>
208
209 <x:template match="processing-instruction('bibliography')">
210 <x:copy-of select="document(concat(substring-before($document-id, '.xml'),'.bbl'))"/>
211 </x:template>
212
213 <x:template match="h:span[@class='cite']">
214 <em>[<a href='#ref:{text()}'><x:value-of select='.'/></a>]</em>
215 </x:template>
216
217 <x:template match="h:span[@class='url']">
218 <a href='{text()}'>
219 <span class='url'><x:value-of select='.'/></span>
220 </a>
221 </x:template>
222
223 <x:template match="processing-instruction('bibliography')" mode="extract-aux">
224 <x:text>\relax
225 </x:text>
226 <x:apply-templates select="//h:span[@class='cite']" mode="extract-aux"/>
227 <x:if test="string-length(.) &gt; 0">
228 <x:call-template name="make-tex-command">
229 <x:with-param name="command">bibdata</x:with-param>
230 <x:with-param name="content">
231 <x:value-of select="normalize-space(.)"/>
232 </x:with-param>
233 </x:call-template>
234 </x:if>
235 </x:template>
236
237 <x:template match="h:span[@class='cite']" mode="extract-aux">
238 <x:call-template name="make-tex-command">
239 <x:with-param name="command">citation</x:with-param>
240 <x:with-param name="content">
241 <x:copy-of select="."/>
242 </x:with-param>
243 </x:call-template>
244 </x:template>
245
246 <x:key name="xrefs" match="h:div" use="@id"/>
247
248 <x:template match="h:span[@class='xref']">
249 <x:variable name="id" select="."/>
250 <a href='#{$id}'>
251 <x:apply-templates select="key('xrefs',$id)" mode="make-section-name"/>
252 </a>
253 </x:template>
254
255 <x:template match="h:span[@class='rcsinfo']">
256 <x:value-of select="substring-before(substring-after(.,': '),' $')"/>
257 </x:template>
258
259 <x:template match="h:h1">
260 <h1 property='dc:title'>
261 <x:apply-templates select="@*"/>
262 <x:apply-templates/>
263 </h1>
264 </x:template>
265
266 <x:template xmlns:owl="http://www.w3.org/2002/07/owl#" match="h:meta">
267 <x:choose>
268 <x:when test="@name='DC.rights'">
269 <link about='' rel='{@name}' href='{@content}'/>
270 </x:when>
271 <x:when test="@name='rcsdate'">
272 <meta about='' property='dcterms:modified'>
273 <x:attribute name='content'>
274 <x:value-of select="translate(substring(@content,8,10),'/','-')"/>
275 <x:text>T</x:text>
276 <x:value-of select="substring(@content,19,8)"/>
277 </x:attribute>
278 </meta>
279 </x:when>
280 <x:when test="@name='purl'">
281 <link about='' rel='dc:identifier' href='{@content}'/>
282 <link about='' rel='owl:sameAs' href='{@content}'/>
283 </x:when>
284 <x:when test="starts-with(@name,'DC.')">
285 <meta about='' content='{@content}'>
286 <x:attribute name="property">dc:<x:value-of select="substring-after(@name, 'DC.')"/>
287 </x:attribute>
288 </meta>
289 </x:when>
290 <x:when test='@property and @content'>
291 <!-- it's a well-formed RDFa meta element, so copy it over -->
292 <x:copy-of select='.'/>
293 </x:when>
294 </x:choose>
295 </x:template>
296
297 <x:template match="h:div[@class='signature']">
298 <x:copy>
299 <x:apply-templates select="@*"/>
300 <x:choose>
301 <x:when test="h:a/@href">
302 <x:attribute name="rel">dc:creator</x:attribute>
303 <x:attribute name="href">
304 <x:value-of select="h:a/@href"/>
305 </x:attribute>
306 </x:when>
307 <x:otherwise>
308 <x:attribute name="property">dc:creator</x:attribute>
309 <x:attribute name="content">
310 <x:value-of select="h:a/text()"/>
311 </x:attribute>
312 </x:otherwise>
313 </x:choose>
314 <x:apply-templates/>
315 </x:copy>
316 </x:template>
317
318 <x:template match="h:div[@class='abstract']">
319 <x:copy>
320 <x:apply-templates select="@*"/>
321 <x:element name='meta' namespace='http://www.w3.org/1999/xhtml'>
322 <x:attribute name='property'>dcterms:abstract</x:attribute>
323 <x:attribute name='about'/>
324 <x:attribute name="content">
325 <x:apply-templates select="h:p[not(@class)]" mode="text-only"/>
326 </x:attribute>
327 </x:element>
328 <x:apply-templates/>
329 </x:copy>
330 </x:template>
331
332 <x:template match="h:q">
333 <x:text></x:text>
334 <x:apply-templates/>
335 <x:text></x:text>
336 </x:template>
337
338 <x:template match="h:p" mode="text-only">
339 <x:value-of select="normalize-space(.)"/>
340 <x:text> </x:text>
341 </x:template>
342
343 <x:template name="make-tex-command">
344 <x:param name="command"/>
345 <x:param name="content"/>
346 <x:text>\</x:text>
347 <x:value-of select="$command"/>
348 <x:text>{</x:text>
349 <x:value-of select="$content"/>
350 <x:text>}
351 </x:text>
352 </x:template>
353
354 </x:stylesheet>

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26