/[volute]/trunk/projects/grid/uws/doc/ivoadoc/ivoarestructure.xslt
ViewVC logotype

Contents of /trunk/projects/grid/uws/doc/ivoadoc/ivoarestructure.xslt

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1247 - (show annotations)
Wed Feb 10 13:11:35 2010 UTC (10 years, 5 months ago) by harripa
File MIME type: text/plain
File size: 17849 byte(s)
correct the handling of the toc processing instruction
1 <?xml version="1.0" encoding="UTF-8"?>
2 <x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform"
3 version="2.0"
4 xmlns:h="http://www.w3.org/1999/xhtml"
5 xmlns="http://www.w3.org/1999/xhtml"
6 xmlns:dc="http://purl.org/dc/elements/1.1/"
7 xmlns:dcterms="http://purl.org/dc/terms/">
8
9 <x:output method="xml"
10 encoding="ISO-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
11 />
12
13 <!--
14 This script is designed to help with the production of IVOA standards - it is derived from a script by Norman Gray, but is different in behaviour in that the document produced by the script is
15 intended to be used as input in the next round of editing.
16
17 Paul Harrison
18
19 The following supports a mildly-enhanced version of XHTML. Most
20 notably, it supports sectioning via nested <div class='section'>
21 elements, with the section title being given by the first
22 <h1><a name="secid"/><span class="secnum">1.1</span> Title</h1> child of the <div>. The <div> class can also
23 be 'section-nonum', with the obvious meaning, and the div can
24 have an 'id' attribute which allows cross-references to it.
25 Cross-references are supported by a <span class='xref'>id</span> element.
26
27 Appendices go in a <div class='appendices'>, and an abstract in
28 <div class='abstract'>
29
30 The <div>s can be collected into a ToC, at a location marked by
31 a <?toc?> PI.
32
33 Bibliography: entries can be marked with <span
34 class='cite'>ref</span>, and these can be collected into a .aux
35 file by running this stylesheet with the parameter 'target'
36 given as 'aux'. The location of the bibliography is marked by a
37 <?bibliography?> PI: this simply reads in a file
38 $document-id.bbl, the generation of which must be managed
39 externally to this script.
40
41
42 xml documents can be literally included (and formatted) with the <?xmlinc href=""?> processing instruction. All text between
43 until the <?xmlinc end?> will be replaced.
44
45 There's also a <span class='url'>url</span>, which formats the
46 URL appropriately, and a
47 <span class='rcsinfo'>$foo: bar $</span>, which extracts the
48 contents 'bar' from the string.
49
50 The output has extra properties added to support RDFa, using
51 information extracted from 'title' and 'abstract', and from
52 <meta name='DC.xxx'> and <meta name='rcsdate'> fields in the <head>
53 -->
54
55 <!-- We include support for RDFa in the following, via: the output doctype,
56 the 'profile' attribute in the head element, and the various 'property'
57 attributes in the text.
58 See <http://www.w3.org/TR/2008/WD-rdfa-syntax-20080221/#docconf>.
59 We also add a GRDDL transformation which independently specifies
60 the RDFa transformation. -->
61
62 <x:param name="target"/>
63
64 <x:param name="document-id">document-id</x:param>
65
66 <x:param name="reloadbib"/>
67
68
69 <!-- process root node -->
70 <x:template match="/">
71 <x:choose>
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 select="child::node()"/>
78 </x:otherwise>
79 </x:choose>
80 </x:template>
81
82
83 <x:template match="h:head">
84 <head profile='http://www.w3.org/1999/xhtml/vocab'>
85 <x:apply-templates select="@*"/>
86 <x:copy-of select="namespace::*[.='http://purl.org/dc/elements/1.1/']"/>
87 <x:apply-templates select="child::node()"/>
88 </head>
89 </x:template>
90
91
92 <x:template match="h:div[@class='section' or @class='section-nonum']">
93
94 <x:copy>
95 <x:apply-templates select="@*"/>
96 <x:variable name='id'>
97 <x:call-template name='make-section-id'/>
98 </x:variable>
99 <x:variable name="level">
100 <x:choose>
101 <x:when test="ancestor::h:div[@class='section']/ancestor::h:div[@class='section']">h4</x:when>
102 <x:when test="ancestor::h:div[@class='section']">h3</x:when>
103 <x:otherwise>h2</x:otherwise>
104 </x:choose>
105 </x:variable>
106 <x:message>section <x:value-of select="$level"/></x:message>
107 <x:element name='{$level}'>
108 <x:element name="a"><x:attribute name='name' select="$id"/>
109 <x:copy-of select="./(h:h2|h:h3|h:h4)/h:a/@*" />
110
111 </x:element>
112 <x:apply-templates select="." mode="make-section-name"/>
113 </x:element>
114 <x:apply-templates select="*[1]/following-sibling::node()"/><!-- perhaps a little dangerous perhaps better to have a template to ignore the first h1 etc after a section... -->
115 </x:copy>
116 </x:template>
117
118 <!-- this is not perfect either - depends how many levels down...
119 <x:template match="h:div[@class='section' or @class='section-nonum']/h1[1]|h2[1]|h3[1]">
120 </x:template>
121 -->
122
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
153 <x:template match="h:div[@class='appendices']">
154 <x:copy>
155 <x:apply-templates select="@*"/>
156
157 <x:apply-templates select="child::node()"/>
158 </x:copy>
159 </x:template>
160
161 <x:template match="h:div" mode="make-toc">
162 <x:variable name="id">
163 <x:call-template name="make-section-id"/>
164 </x:variable>
165 <li>
166 <a href='#{$id}'>
167 <x:apply-templates select='.' mode='make-section-name'/>
168 </a>
169 <x:if test="h:div[@class='section' or @class='section-nonum']">
170 <ul>
171 <x:apply-templates select="h:div[@class='section' or @class='section-nonum']" mode="make-toc"/>
172 </ul>
173 </x:if>
174 </li>
175 </x:template>
176
177 <x:template match="h:div[processing-instruction()[1][count(preceding-sibling::element()) = 0]]">
178 <!-- the processing instructions will replace everything with the enclosing div if they are first - used for the toc, bibliography and xmlinc processing instucctions-->
179 <x:copy>
180 <x:choose>
181 <x:when test="child::processing-instruction('bibliography') and not($reloadbib)">
182 <x:apply-templates/>
183 </x:when>
184 <x:otherwise>
185 <x:apply-templates select="child::processing-instruction()"/>
186 </x:otherwise>
187 </x:choose>
188
189 </x:copy>
190 </x:template>
191
192 <x:template match="processing-instruction('toc')">
193 <x:processing-instruction name="toc"/>
194 <div id='toc' class='toc'>
195 <ul>
196 <x:apply-templates select="//h:div[@class='body']/h:div[@class='section' or @class='section-nonum']|//h:div[@class='body']/h:div[@class='appendices']/h:div" mode="make-toc"/>
197 </ul>
198 </div>
199
200 </x:template>
201
202 <x:template name="make-section-id">
203
204 <x:choose>
205 <x:when test="child::*[1]/h:a/@id">
206 <x:value-of select="child::*[1]/h:a/@id"/>
207 </x:when>
208 <x:otherwise>
209 <x:value-of select="generate-id()"/>
210 </x:otherwise>
211 </x:choose>
212 </x:template>
213
214 <x:template match="h:div" mode="make-section-name">
215 <x:element name="span"><x:attribute name="class" select="'secnum'"></x:attribute>
216 <x:apply-templates select="." mode="make-section-number"/>
217 </x:element>
218 <x:apply-templates select="child::*[1]/text()"/>
219 </x:template>
220
221 <x:template match="h:div" mode="make-section-number"><!-- would named template be better? -->
222 <x:choose>
223 <x:when test="ancestor-or-self::h:div[@class='section-nonum']"/>
224 <x:when test="ancestor::h:div[@class='appendices']">
225 <x:text>Appendix </x:text>
226 <x:number count="h:div[@class='section']" level="multiple" format="A.1."/>
227 <x:text> </x:text>
228 </x:when>
229 <x:otherwise>
230 <x:number count="h:div[@class='section']" level="multiple" format="1.1."/>
231 <x:text> </x:text>
232 </x:otherwise>
233 </x:choose>
234
235
236 </x:template>
237
238 <x:template match="processing-instruction('bibliography')">
239 <x:copy/>
240 <x:choose><x:when test="contains(.,'replace')">
241
242 <!-- think of better way to get the document id in -->
243 <x:if test="$document-id ne 'document-id'">
244 <x:copy-of select="document(concat(substring-before($document-id, '.xml'),'.bbl'))"/>
245 </x:if>
246 </x:when></x:choose>
247 </x:template>
248
249 <x:template match="h:cite">
250 <!-- need to do this as numbered along with bibstyle... -->
251 <x:copy>
252 <x:variable name="ref">
253 <x:choose>
254 <x:when test="h:a/@href">
255 <x:value-of select="substring-after(h:a/@href,'#')"/>
256 </x:when>
257 <x:otherwise>
258 <x:value-of select="."/>
259 </x:otherwise>
260 </x:choose>
261 </x:variable>
262 [<a href='#{$ref}'><x:value-of select='$ref'/></a>]
263 </x:copy>
264 </x:template>
265
266 <x:template match="h:span[@class='url']">
267 <a href='{text()}'>
268 <span class='url'><x:value-of select='.'/></span>
269 </a>
270 </x:template>
271
272
273 <x:key name="xrefs" match="h:div[(h:h1|h:h2|h:h3|h:h4|h:h5|h:h6)/h:a]" use="*/h:a/@id"/><!-- can only reference sections at the moment -->
274
275 <x:template match="h:span[@class='xref']">
276 <span class="xref">
277
278 <x:variable name="id">
279 <x:choose>
280 <x:when test="h:a/@href">
281 <x:value-of select="substring-after(h:a/@href, '#')"/>
282 </x:when>
283 <x:otherwise>
284 <x:value-of select="."/> <!-- can just put in the xref span -->
285 </x:otherwise>
286 </x:choose>
287 </x:variable>
288 <x:choose>
289 <x:when test="key('xrefs',$id)">
290 <x:message>putting in xref <x:value-of select="$id"/></x:message>
291 </x:when>
292 <x:otherwise>
293 <x:message >error putting in xref <x:value-of select="$id"/> - destination does not exist </x:message>
294 </x:otherwise>
295 </x:choose>
296 <a href='#{$id}'>
297 <x:apply-templates select="key('xrefs',$id)" mode="make-section-number"/>
298 </a>
299 </span>
300 </x:template>
301
302 <x:template match="h:span[@class='rcsinfo']">
303 <x:value-of select="substring-before(substring-after(.,': '),' $')"/>
304 </x:template>
305
306
307 <!-- maybe later
308 <x:template xmlns:owl="http://www.w3.org/2002/07/owl#" match="h:meta">
309 <x:choose>
310 <x:when test="@name='DC.rights'">
311 <link about='' rel='{@name}' href='{@content}'/>
312 </x:when>
313 <x:when test="@name='rcsdate'">
314 <meta about='' property='dcterms:modified'>
315 <x:attribute name='content'>
316 <x:value-of select="translate(substring(@content,8,10),'/','-')"/>
317 <x:text>T</x:text>
318 <x:value-of select="substring(@content,19,8)"/>
319 </x:attribute>
320 </meta>
321 </x:when>
322 <x:when test="@name='purl'">
323 <link about='' rel='dc:identifier' href='{@content}'/>
324 <link about='' rel='owl:sameAs' href='{@content}'/>
325 </x:when>
326 <x:when test="starts-with(@name,'DC.')">
327 <meta about='' content='{@content}'>
328 <x:attribute name="property">dc:<x:value-of select="substring-after(@name, 'DC.')"/>
329 </x:attribute>
330 </meta>
331 </x:when>
332 <x:when test='@property and @content'>
333
334 <x:copy-of select='.'/>
335 </x:when>
336 </x:choose>
337 </x:template>
338 -->
339
340 <x:template match="h:div[@class='signature']">
341 <x:copy>
342 <x:apply-templates select="@*"/>
343 <x:choose>
344 <x:when test="h:a/@href">
345 <x:attribute name="rel">dc:creator</x:attribute>
346 <x:attribute name="href">
347 <x:value-of select="h:a/@href"/>
348 </x:attribute>
349 </x:when>
350 <x:otherwise>
351 <x:attribute name="property">dc:creator</x:attribute>
352 <x:attribute name="content">
353 <x:value-of select="h:a/text()"/>
354 </x:attribute>
355 </x:otherwise>
356 </x:choose>
357 <x:apply-templates/>
358 </x:copy>
359 </x:template>
360
361 <x:template match="h:div[@class='abstract']">
362 <x:copy>
363 <x:apply-templates select="@*"/>
364 <x:element name='meta' namespace='http://www.w3.org/1999/xhtml'>
365 <x:attribute name='property'>dcterms:abstract</x:attribute>
366 <x:attribute name='about'/>
367 <x:attribute name="content">
368 <x:apply-templates select="h:p[not(@class)]" mode="text-only"/>
369 </x:attribute>
370 </x:element>
371 <x:apply-templates select="child::node()"/>
372 </x:copy>
373 </x:template>
374
375 <!-- <x:template match="h:q">
376 <x:text>“</x:text>
377 <x:apply-templates/>
378 <x:text>”</x:text>
379 </x:template> -->
380
381 <x:template match="h:p" mode="text-only">
382 <x:value-of select="normalize-space(.)"/>
383 <x:text> </x:text>
384 </x:template>
385
386 <x:template match="processing-instruction('incxml')">
387 <x:copy/>
388 <x:choose>
389 <x:when test="starts-with(., 'href')">
390 <x:analyze-string regex="href=['&quot;]([^'&quot;]+)['&quot;]" select=".">
391 <x:matching-substring>
392 <x:message>Including xml from <x:value-of select="regex-group(1)"/></x:message>
393 <x:apply-templates select="document(regex-group(1))" mode="printxml"></x:apply-templates>
394 </x:matching-substring>
395 </x:analyze-string>
396 </x:when>
397
398 </x:choose>
399 </x:template>
400
401
402 <!-- default identity transformation -->
403 <x:template match="node()|@*">
404 <x:copy>
405 <x:apply-templates select="node()|@*"/>
406 </x:copy>
407 </x:template>
408
409 <!-- printxml stuff -->
410
411 <x:template match="/" mode="printxml" >
412 <div class="viewxml">
413 <x:apply-templates select="child::node()" mode="printxml"/>
414 </div>
415 </x:template>
416
417 <x:template match="/*" mode="printxml" priority="1"><!-- try to add the namespaces for the root element -->
418 <x:message>in root element <x:value-of select="name(.)"/></x:message>
419 <div class="element">
420 <span class="markup">&lt;</span><span class="start-tag"><x:value-of select="name(.)"/></span><x:apply-templates select="@*" mode="printxml"/>
421 <x:variable name="v" select="."/>
422 <x:for-each select="in-scope-prefixes(.)">
423 <x:text> </x:text><span class="attribute-name"><x:text>xmlns:</x:text><x:value-of select="."/></span><span class="markup">=</span><span class="attribute-value">"<x:value-of select="namespace-uri-for-prefix(., $v)"/>"</span>
424 </x:for-each>
425 <span class="markup">&gt;</span>
426 <x:apply-templates select="child::node()" mode="printxml"/>
427 <span class="markup">&lt;/</span><span class="end-tag"><x:value-of select="name(.)"/></span><span class="markup">&gt;</span>
428 </div>
429 </x:template>
430
431
432 <x:template match="processing-instruction()" mode="printxml">
433 <div class="indent pi">
434 <x:text>&lt;?</x:text>
435 <x:value-of select="name(.)"/>
436 <x:text> </x:text>
437 <x:value-of select="."/>
438 <x:text>?&gt;</x:text>
439 </div>
440 </x:template>
441
442 <x:template match="comment()" mode="printxml">
443 <x:message>comment</x:message>
444 <div class="comment"><x:text>&lt;!--</x:text><x:value-of select="."/><x:text>--&gt;</x:text></div>
445 </x:template>
446
447
448 <x:template match="*" mode="printxml" >
449 <x:message>all <x:value-of select="name(.)"/></x:message>
450 <div class="indent">
451 <span class="markup">&lt;</span>
452 <span class="start-tag"><x:value-of select="name(.)"/></span>
453 <x:apply-templates select="@*" mode="printxml"/>
454 <span class="markup">/&gt;</span>
455 </div>
456 </x:template>
457
458 <!-- this template causes ambiguity with the next one - seems harmless in saxon, but need to understand how to remove - possibly because of newlines... -->
459 <x:template match="*[text()]" mode="printxml">
460 <div class="indent">
461 <span class="markup">&lt;</span>
462 <span class="start-tag"><x:value-of select="name(.)"/></span>
463 <x:apply-templates select="@*" mode="printxml"/>
464 <span class="markup">&gt;</span>
465 <span class="text"><x:value-of select="."/></span>
466 <span class="markup">&lt;/</span>
467 <span class="end-tag"><x:value-of select="name(.)"/></span>
468 <span class="markup">&gt;</span>
469 </div>
470 </x:template>
471
472
473 <x:template match="*[element()]" mode="printxml" >
474 <div class="element">
475 <span class="markup">&lt;</span><span class="start-tag"><x:value-of select="name(.)"/></span><x:apply-templates select="@*" mode="printxml"/><span class="markup">&gt;</span>
476 <x:apply-templates select="child::node()" mode="printxml"/>
477 <span class="markup">&lt;/</span><span class="end-tag"><x:value-of select="name(.)"/></span><span class="markup">&gt;</span>
478 </div>
479 </x:template>
480
481
482
483 <x:template match="@*" mode="printxml">
484 <x:text> </x:text><span class="attribute-name"><x:value-of select="name(.)"/></span><span class="markup">=</span><span class="attribute-value">"<x:value-of select="."/>"</span>
485 </x:template>
486
487
488 <x:template match="text()" mode="printxml">
489 <x:if test="normalize-space(.)">
490 <div class="indent text"><x:value-of select="."/></div>
491 </x:if>
492 </x:template>
493
494
495
496 </x:stylesheet>

Properties

Name Value
svn:mergeinfo
svn:mime-type text/plain

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