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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 856 - (show annotations)
Thu Nov 6 14:02:08 2008 UTC (12 years ago) by harripa
File MIME type: text/plain
File size: 15984 byte(s)
first iteration on making a ivoa publication environment based on Norman's scripts, but with different intent of being able to edit/restructure/edit in the same document.
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="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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
67 <!-- process root node -->
68 <x:template match="/">
69 <x:choose>
70 <x:when test="$target='aux'">
71 <x:apply-templates select="//processing-instruction('bibliography')"
72 mode="extract-aux"/>
73 </x:when>
74 <x:when test="$target">
75 <x:message terminate="yes">Unrecognised target <x:value-of select="$target"/>
76 </x:message>
77 </x:when>
78 <x:otherwise>
79 <x:apply-templates select="child::node()"/>
80 </x:otherwise>
81 </x:choose>
82 </x:template>
83
84
85 <x:template match="h:head">
86 <head profile='http://www.w3.org/1999/xhtml/vocab'>
87 <x:apply-templates select="@*"/>
88 <x:copy-of select="namespace::*[.='http://purl.org/dc/elements/1.1/']"/>
89 <x:apply-templates select="child::node()"/>
90 </head>
91 </x:template>
92
93
94 <x:template match="h:div[@class='section' or @class='section-nonum']">
95
96 <x:copy>
97 <x:apply-templates select="@*"/>
98 <x:variable name='id'>
99 <x:call-template name='make-section-id'/>
100 </x:variable>
101 <x:variable name="level">
102 <x:choose>
103 <x:when test="ancestor::h:div[@class='section']/ancestor::h:div[@class='section']">h4</x:when>
104 <x:when test="ancestor::h:div[@class='section']">h3</x:when>
105 <x:otherwise>h2</x:otherwise>
106 </x:choose>
107 </x:variable>
108 <x:message>section <x:value-of select="$level"/></x:message>
109 <x:element name='{$level}'>
110 <x:element name="a"><x:attribute name='name' select="$id"/></x:element>
111 <x:apply-templates select="." mode="make-section-name"/>
112 </x:element>
113 <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... -->
114 </x:copy>
115 </x:template>
116
117 <!-- this is not perfect either - depends how many levels down...
118 <x:template match="h:div[@class='section' or @class='section-nonum']/h1[1]|h2[1]|h3[1]">
119 </x:template>
120 -->
121
122 <!--
123 <x:template match="h:div[@class='section' or @class='section-nonum']">
124 <x:variable name="id">
125 <x:call-template name="make-section-id"/>
126 </x:variable>
127 <x:variable name="level">
128 <x:choose>
129 <x:when test="ancestor::h:div[@class='section']/ancestor::h:div[@class='section']">h4</x:when>
130 <x:when test="ancestor::h:div[@class='section']">h3</x:when>
131 <x:otherwise>h2</x:otherwise>
132 </x:choose>
133 </x:variable>
134 <x:element name="{$level}" namespace='http://www.w3.org/1999/xhtml'>
135 <x:if test="@id">
136 <x:attribute name='class'>hlink</x:attribute>
137 </x:if>
138 <x:apply-templates select="." mode="make-section-name"/>
139 <x:element name='a' namespace='http://www.w3.org/1999/xhtml'>
140 <x:attribute name='name'><x:value-of select='$id'/></x:attribute>
141 <x:if test="@id">
142 <x:attribute name='href'>#<x:value-of select='$id'/></x:attribute>
143 <x:text> [link here]</x:text>
144 </x:if>
145 </x:element>
146 </x:element>
147 <x:apply-templates/>
148 </x:template>
149 -->
150
151
152 <x:template match="h:div[@class='appendices']">
153 <x:copy>
154 <x:apply-templates select="@*"/>
155 <x:element name="h2"><x:text>Appendices</x:text></x:element>
156 <x:apply-templates select="child::node()"/>
157 </x:copy>
158 </x:template>
159
160 <x:template match="h:div" mode="make-toc">
161 <x:variable name="id">
162 <x:call-template name="make-section-id"/>
163 </x:variable>
164 <li>
165 <a href='#{$id}'>
166 <x:apply-templates select='.' mode='make-section-name'/>
167 </a>
168 <x:if test="h:div[@class='section' or @class='section-nonum']">
169 <ul>
170 <x:apply-templates select="h:div[@class='section' or @class='section-nonum']" mode="make-toc"/>
171 </ul>
172 </x:if>
173 </li>
174 </x:template>
175
176 <x:template match="processing-instruction('toc')">
177 <div id='toc' class='toc'>
178 <ul>
179 <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"/>
180 </ul>
181 </div>
182 </x:template>
183
184 <x:template name="make-section-id">
185
186 <x:choose>
187 <x:when test="child::*[1]/h:a/@id">
188 <x:value-of select="child::*[1]/h:a/@id"/>
189 </x:when>
190 <x:otherwise>
191 <x:value-of select="generate-id()"/>
192 </x:otherwise>
193 </x:choose>
194 </x:template>
195
196 <x:template match="h:div" mode="make-section-name">
197 <x:element name="span"><x:attribute name="class" select="'secnum'"></x:attribute>
198 <x:choose>
199 <x:when test="ancestor-or-self::h:div[@class='section-nonum']"/>
200 <x:when test="ancestor::h:div[@class='appendices']">
201 <x:number count="h:div[@class='section']" level="multiple" format="A.1."/>
202 <x:text> </x:text>
203 </x:when>
204 <x:otherwise>
205 <x:number count="h:div[@class='section']" level="multiple" format="1.1."/>
206 <x:text> </x:text>
207 </x:otherwise>
208 </x:choose>
209 </x:element>
210 <x:apply-templates select="child::*[1]/text()"/>
211 </x:template>
212
213 <x:template match="processing-instruction('bibliography')">
214 <x:copy/>
215 <!-- think of better way to get the document id in -->
216 <x:if test="$document-id ne 'document-id'">
217 <x:copy-of select="document(concat(substring-before($document-id, '.xml'),'.bbl'))"/>
218 </x:if>
219 </x:template>
220
221 <x:template match="h:span[@class='cite']">
222 <em>[<a href='#ref:{text()}'><x:value-of select='.'/></a>]</em>
223 </x:template>
224
225 <x:template match="h:span[@class='url']">
226 <a href='{text()}'>
227 <span class='url'><x:value-of select='.'/></span>
228 </a>
229 </x:template>
230
231 <x:template match="processing-instruction('bibliography')" mode="extract-aux">
232 <x:text>\relax
233 </x:text>
234 <x:apply-templates select="//h:span[@class='cite']" mode="extract-aux"/>
235 <x:if test="string-length(.) &gt; 0">
236 <x:call-template name="make-tex-command">
237 <x:with-param name="command">bibdata</x:with-param>
238 <x:with-param name="content">
239 <x:value-of select="normalize-space(.)"/>
240 </x:with-param>
241 </x:call-template>
242 </x:if>
243 </x:template>
244
245 <x:template match="h:span[@class='cite']" mode="extract-aux">
246 <x:call-template name="make-tex-command">
247 <x:with-param name="command">citation</x:with-param>
248 <x:with-param name="content">
249 <x:copy-of select="."/>
250 </x:with-param>
251 </x:call-template>
252 </x:template>
253
254 <x:key name="xrefs" match="h:div/h1|h2|h3|h4|h5|h6/a" use="@id"/>
255
256 <x:template match="h:span[@class='xref']">
257 <x:variable name="id" select="."/>
258 <a href='#{$id}'>
259 <x:apply-templates select="key('xrefs',$id)" mode="make-section-name"/>
260 </a>
261 </x:template>
262
263 <x:template match="h:span[@class='rcsinfo']">
264 <x:value-of select="substring-before(substring-after(.,': '),' $')"/>
265 </x:template>
266
267
268 <!-- maybe later
269 <x:template xmlns:owl="http://www.w3.org/2002/07/owl#" match="h:meta">
270 <x:choose>
271 <x:when test="@name='DC.rights'">
272 <link about='' rel='{@name}' href='{@content}'/>
273 </x:when>
274 <x:when test="@name='rcsdate'">
275 <meta about='' property='dcterms:modified'>
276 <x:attribute name='content'>
277 <x:value-of select="translate(substring(@content,8,10),'/','-')"/>
278 <x:text>T</x:text>
279 <x:value-of select="substring(@content,19,8)"/>
280 </x:attribute>
281 </meta>
282 </x:when>
283 <x:when test="@name='purl'">
284 <link about='' rel='dc:identifier' href='{@content}'/>
285 <link about='' rel='owl:sameAs' href='{@content}'/>
286 </x:when>
287 <x:when test="starts-with(@name,'DC.')">
288 <meta about='' content='{@content}'>
289 <x:attribute name="property">dc:<x:value-of select="substring-after(@name, 'DC.')"/>
290 </x:attribute>
291 </meta>
292 </x:when>
293 <x:when test='@property and @content'>
294
295 <x:copy-of select='.'/>
296 </x:when>
297 </x:choose>
298 </x:template>
299 -->
300
301 <x:template match="h:div[@class='signature']">
302 <x:copy>
303 <x:apply-templates select="@*"/>
304 <x:choose>
305 <x:when test="h:a/@href">
306 <x:attribute name="rel">dc:creator</x:attribute>
307 <x:attribute name="href">
308 <x:value-of select="h:a/@href"/>
309 </x:attribute>
310 </x:when>
311 <x:otherwise>
312 <x:attribute name="property">dc:creator</x:attribute>
313 <x:attribute name="content">
314 <x:value-of select="h:a/text()"/>
315 </x:attribute>
316 </x:otherwise>
317 </x:choose>
318 <x:apply-templates/>
319 </x:copy>
320 </x:template>
321
322 <x:template match="h:div[@class='abstract']">
323 <x:copy>
324 <x:apply-templates select="@*"/>
325 <x:element name='meta' namespace='http://www.w3.org/1999/xhtml'>
326 <x:attribute name='property'>dcterms:abstract</x:attribute>
327 <x:attribute name='about'/>
328 <x:attribute name="content">
329 <x:apply-templates select="h:p[not(@class)]" mode="text-only"/>
330 </x:attribute>
331 </x:element>
332 <x:apply-templates select="child::node()"/>
333 </x:copy>
334 </x:template>
335
336 <!-- <x:template match="h:q">
337 <x:text>“</x:text>
338 <x:apply-templates/>
339 <x:text>”</x:text>
340 </x:template> -->
341
342 <x:template match="h:p" mode="text-only">
343 <x:value-of select="normalize-space(.)"/>
344 <x:text> </x:text>
345 </x:template>
346
347 <x:template name="make-tex-command">
348 <x:param name="command"/>
349 <x:param name="content"/>
350 <x:text>\</x:text>
351 <x:value-of select="$command"/>
352 <x:text>{</x:text>
353 <x:value-of select="$content"/>
354 <x:text>}
355 </x:text>
356 </x:template>
357
358 <x:template match="processing-instruction('incxml')">
359 <x:copy/>
360 <x:choose>
361 <x:when test="starts-with(., 'href')">
362 <x:analyze-string regex="href=['&quot;]([^'&quot;]+)['&quot;]" select=".">
363 <x:matching-substring>
364 <x:message>Including xml from <x:value-of select="regex-group(1)"/></x:message>
365 <x:apply-templates select="document(regex-group(1))" mode="printxml"></x:apply-templates>
366 </x:matching-substring>
367 </x:analyze-string>
368 </x:when>
369 </x:choose>
370 </x:template>
371
372
373 <!-- default identity transformation -->
374 <x:template match="node()|@*">
375 <x:copy>
376 <x:apply-templates select="node()|@*"/>
377 </x:copy>
378 </x:template>
379
380 <!-- printxml stuff -->
381
382 <x:template match="/" mode="printxml" >
383 <div class="viewxml">
384 <x:apply-templates select="child::node()" mode="printxml"/>
385 </div>
386 </x:template>
387
388 <x:template match="processing-instruction()" mode="printxml">
389 <div class="indent pi">
390 <x:text>&lt;?</x:text>
391 <x:value-of select="name(.)"/>
392 <x:text> </x:text>
393 <x:value-of select="."/>
394 <x:text>?&gt;</x:text>
395 </div>
396 </x:template>
397
398 <x:template match="comment()" mode="printxml">
399 <x:message>comment</x:message>
400 <div class="comment"><x:text>&lt;!--</x:text><x:value-of select="."/><x:text>--&gt;</x:text></div>
401 </x:template>
402
403
404 <x:template match="*" mode="printxml">
405 <x:message>all</x:message>
406 <div class="indent">
407 <span class="markup">&lt;</span>
408 <span class="start-tag"><x:value-of select="name(.)"/></span>
409 <x:apply-templates select="@*" mode="printxml"/>
410 <span class="markup">/&gt;</span>
411 </div>
412 </x:template>
413
414 <!-- this template causes ambiguity with the next one - seems harmless in saxon, but need to understand how to remove -->
415 <x:template match="*[text()]" mode="printxml">
416 <div class="indent">
417 <span class="markup">&lt;</span>
418 <span class="start-tag"><x:value-of select="name(.)"/></span>
419 <x:apply-templates select="@*" mode="printxml"/>
420 <span class="markup">&gt;</span>
421 <span class="text"><x:value-of select="."/></span>
422 <span class="markup">&lt;/</span>
423 <span class="end-tag"><x:value-of select="name(.)"/></span>
424 <span class="markup">&gt;</span>
425 </div>
426 </x:template>
427
428 <x:template match="*[element()]" mode="printxml">
429 <div class="element">
430 <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>
431 <x:apply-templates select="child::node()" mode="printxml"/>
432 <span class="markup">&lt;/</span><span class="end-tag"><x:value-of select="name(.)"/></span><span class="markup">&gt;</span>
433 </div>
434 </x:template>
435
436 <x:template match="@*" mode="printxml">
437 <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>
438 </x:template>
439
440 <x:template match="text()" mode="printxml">
441 <x:if test="normalize-space(.)">
442 <div class="indent text"><x:value-of select="."/></div>
443 </x:if>
444 </x:template>
445
446
447
448 </x:stylesheet>

Properties

Name Value
svn:mime-type text/plain

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