Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / common2 / linking.xsl @ 187

History | View | Annotate | Download (15.4 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0"
3
		xmlns:xs="http://www.w3.org/2001/XMLSchema"                
4
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
                exclude-result-prefixes="tei xs"
6
                version="2.0">
7
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
8
      <desc>
9
         <p> TEI stylesheet dealing with elements from the linking module. </p>
10
         <p>This software is dual-licensed:
11

    
12
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
13
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
14

    
15
2. http://www.opensource.org/licenses/BSD-2-Clause
16
		
17
All rights reserved.
18

    
19
Redistribution and use in source and binary forms, with or without
20
modification, are permitted provided that the following conditions are
21
met:
22

    
23
* Redistributions of source code must retain the above copyright
24
notice, this list of conditions and the following disclaimer.
25

    
26
* Redistributions in binary form must reproduce the above copyright
27
notice, this list of conditions and the following disclaimer in the
28
documentation and/or other materials provided with the distribution.
29

    
30
This software is provided by the copyright holders and contributors
31
"as is" and any express or implied warranties, including, but not
32
limited to, the implied warranties of merchantability and fitness for
33
a particular purpose are disclaimed. In no event shall the copyright
34
holder or contributors be liable for any direct, indirect, incidental,
35
special, exemplary, or consequential damages (including, but not
36
limited to, procurement of substitute goods or services; loss of use,
37
data, or profits; or business interruption) however caused and on any
38
theory of liability, whether in contract, strict liability, or tort
39
(including negligence or otherwise) arising in any way out of the use
40
of this software, even if advised of the possibility of such damage.
41
</p>
42
         <p>Author: See AUTHORS</p>
43
         <p>Id: $Id: linking.xsl 10057 2012-01-21 16:57:14Z rahtz $</p>
44
         <p>Copyright: 2011, TEI Consortium</p>
45
      </desc>
46
   </doc>
47
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
48
      <desc>Process element  in xref mode</desc>
49
   </doc>
50
  <xsl:template match="tei:TEI" mode="xref">
51
      <xsl:apply-templates select="tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title[1]"/>
52
  </xsl:template>
53

    
54
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
55
      <desc>Process elements text in xref mode</desc>
56
   </doc>
57
  <xsl:template match="tei:text" mode="xref">
58
   <xsl:choose>
59
     <xsl:when test="tei:head">
60
       <xsl:apply-templates select="tei:head" mode="plain"/>
61
     </xsl:when>
62
     <xsl:when test="tei:body/tei:head">
63
       <xsl:apply-templates select="tei:body/tei:head" mode="plain"/>
64
     </xsl:when>
65
     <xsl:when test="tei:front//tei:titlePart/tei:title">
66
       <xsl:apply-templates select="tei:front//tei:titlePart/tei:titl" mode="plain"/>
67
     </xsl:when>
68
     <xsl:otherwise>
69
       <xsl:text>Text </xsl:text>
70
       <xsl:number/>
71
     </xsl:otherwise>
72
   </xsl:choose>
73
  </xsl:template>
74

    
75
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
76
      <desc>Process element anchor|tei:p in xref mode</desc>
77
   </doc>
78
  <xsl:template match="tei:anchor|tei:p" mode="xref">
79
      <xsl:text>here</xsl:text>
80
  </xsl:template>
81
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
82
      <desc>Process element bibl</desc>
83
   </doc>
84
  <xsl:template match="tei:bibl" mode="xref">
85
      <xsl:text>[</xsl:text>
86
      <xsl:number/>
87
      <xsl:text>]</xsl:text>
88
  </xsl:template>
89

    
90
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
91
      <desc>Process element s
92
      tei:div|tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6 in
93
      xref mode<param name="minimal">whether to make a link with just numbers or with
94
      text too</param>
95
      </desc>
96
   </doc>
97
  <xsl:template match="tei:div|tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6"
98
                 mode="xref">
99
      <xsl:param name="minimal">false</xsl:param>
100
      <xsl:call-template name="header">
101
         <xsl:with-param name="minimal" select="$minimal"/>
102
         <xsl:with-param name="display">plain</xsl:with-param>
103
      </xsl:call-template>
104
  </xsl:template>
105
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
106
      <desc>Process element ptr in xref mode</desc>
107
   </doc>
108
  <xsl:template match="tei:ptr">
109
      <xsl:call-template name="makeTEILink">
110
         <xsl:with-param name="ptr" select="true()"/>
111
      </xsl:call-template>
112
  </xsl:template>
113
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
114
      <desc>Process element ref</desc>
115
   </doc>
116
  <xsl:template match="tei:ref">
117
      <xsl:call-template name="makeTEILink">
118
         <xsl:with-param name="ptr" select="false()"/>
119
      </xsl:call-template>
120
  </xsl:template>
121
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
122
      <desc>[common] Making a heading for something
123
         <param name="minimal">whether to display headings</param>
124
         <param name="toc">whether this is making a TOC entry</param>
125
         <param name="display">detail of display (full, simple, plain), ie
126
    whether markup is followed</param>
127
      </desc>
128
   </doc>
129
  <xsl:template name="header">
130
      <xsl:param name="minimal">false</xsl:param>
131
      <xsl:param name="toc"/>
132
      <xsl:param name="display">full</xsl:param>
133
      <xsl:variable name="depth">
134
         <xsl:apply-templates mode="depth" select="."/>
135
      </xsl:variable>
136
      <xsl:call-template name="formatHeadingNumber">
137
         <xsl:with-param name="toc">
138
	   <xsl:value-of select="$toc"/>
139
         </xsl:with-param>
140
         <xsl:with-param name="text">
141
            <xsl:choose>
142
               <xsl:when test="local-name(.) = 'TEI'"/>
143
               <xsl:when test="$depth &gt; $numberHeadingsDepth"> </xsl:when>
144
               <xsl:when test="self::tei:text">
145
		 <xsl:number/>
146
		 <xsl:call-template name="headingNumberSuffix"/>
147
	       </xsl:when>
148
               <xsl:when test="ancestor::tei:back">
149
                  <xsl:if test="$numberBackHeadings='true'">
150
                     <xsl:call-template name="i18n">
151
                        <xsl:with-param name="word">appendixWords</xsl:with-param>
152
                     </xsl:call-template>
153
                     <xsl:text> </xsl:text>
154
                     <xsl:call-template name="numberBackDiv"/>
155
                     <xsl:if test="$minimal='false'">
156
                        <xsl:value-of select="$numberSpacer"/>
157
                     </xsl:if>
158
                  </xsl:if>
159
               </xsl:when>
160
               <xsl:when test="ancestor::tei:front">
161
                  <xsl:if test="$numberFrontHeadings='true'">
162
                     <xsl:call-template name="numberFrontDiv">
163
		       <xsl:with-param name="minimal">
164
			 <xsl:value-of select="$minimal"/>
165
		       </xsl:with-param>
166
		     </xsl:call-template>
167
                  </xsl:if>
168
               </xsl:when>
169
               <xsl:when test="$numberHeadings ='true'">
170
                  <xsl:choose>
171
                     <xsl:when test="$prenumberedHeadings='true'">
172
                        <xsl:value-of select="@n"/>
173
                     </xsl:when>
174
                     <xsl:otherwise>
175
                        <xsl:call-template name="numberBodyDiv"/>
176
                     </xsl:otherwise>
177
                  </xsl:choose>
178
                  <xsl:if test="$minimal='false'">
179
                     <xsl:call-template name="headingNumberSuffix"/>
180
                  </xsl:if>
181
               </xsl:when>
182
            </xsl:choose>
183
         </xsl:with-param>
184
      </xsl:call-template>
185
      <xsl:if test="$minimal='false'">
186
         <xsl:choose>
187
            <xsl:when test="local-name(.) = 'TEI'">
188
               <xsl:apply-templates select="tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title[1]"/>
189
            </xsl:when>
190
            <xsl:when test="not($toc='')">
191
	      <xsl:call-template name="makeInternalLink">
192
		<xsl:with-param name="dest">
193
		  <xsl:value-of select="$toc"/>
194
		</xsl:with-param>
195
		<xsl:with-param name="class">
196
		  <xsl:value-of select="$class_toc"/>
197
		  <xsl:text> </xsl:text>
198
		  <xsl:value-of select="concat($class_toc,'_',$depth)"/>
199
		</xsl:with-param>
200
		<xsl:with-param name="body">
201
		  <xsl:choose>
202
		    <xsl:when test="not(tei:head) and tei:body/tei:head">
203
			<xsl:apply-templates mode="plain" select="tei:body/tei:head"/>
204
		    </xsl:when>	
205
		    <xsl:when test="not(tei:head) and tei:front//tei:titlePart/tei:title">
206
			<xsl:apply-templates mode="plain" select="tei:front//tei:titlePart/tei:title"/>
207
		    </xsl:when>	
208
		    <xsl:when test="tei:head">
209
			<xsl:apply-templates mode="plain" select="tei:head"/>
210
		    </xsl:when>
211
		    <xsl:when test="$autoHead='true'">
212
		      <xsl:call-template name="autoMakeHead">
213
			<xsl:with-param name="display" select="$display"/>
214
		      </xsl:call-template>
215
		    </xsl:when>
216
		    <xsl:otherwise>
217
		      <xsl:number/>
218
		    </xsl:otherwise>
219
		  </xsl:choose>
220
		</xsl:with-param>
221
	      </xsl:call-template>
222
            </xsl:when>
223
            <xsl:when test="$autoHead='true'">
224
	      <xsl:choose>
225
		<xsl:when test="($outputTarget='epub' or $outputTarget='epub3') and
226
				not(tei:head)"/>
227
		<xsl:otherwise>
228
		  <xsl:call-template name="autoMakeHead">
229
		    <xsl:with-param name="display" select="$display"/>
230
		  </xsl:call-template>
231
		</xsl:otherwise>
232
	      </xsl:choose>
233
            </xsl:when>
234
            <xsl:when test="$display='plain'">
235
               <xsl:for-each select="tei:head">
236
		 <xsl:apply-templates mode="plain"/>
237
	       </xsl:for-each>
238
            </xsl:when>
239
            <xsl:when test="$display='simple'">
240
               <xsl:for-each select="tei:head">
241
		 <xsl:apply-templates mode="plain"/>
242
	       </xsl:for-each>
243
            </xsl:when>
244
	    <xsl:when test="self::tei:index">
245
	      <xsl:value-of select="substring(tei:term,1,10)"/>
246
	      <xsl:text>…</xsl:text>
247
	    </xsl:when>
248
	    <xsl:when test="not(tei:head)">
249
	      <xsl:value-of select="substring(normalize-space(.),1,10)"/>
250
	      <xsl:text>…</xsl:text>
251
	    </xsl:when>
252
            <xsl:otherwise>
253
               <xsl:apply-templates select="tei:head" mode="makeheading"/>
254
            </xsl:otherwise>
255
         </xsl:choose>
256
      </xsl:if>
257
  </xsl:template>
258

    
259
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
260
      <desc>
261
         <p>[common] processing the number portion of a heading</p>
262
         <p>By default, the text is printed as is. You may
263
    wish to colour it, align it, etc</p>
264
         <param name="text"/>
265
      </desc>
266
   </doc>
267
  <xsl:template name="formatHeadingNumber">
268
      <xsl:param name="text"/>
269
      <xsl:param name="toc"/>
270
      <xsl:copy-of select="$text"/>
271
  </xsl:template>
272

    
273
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
274
      <desc>
275
         <p>[common] Making a heading for something, and making sure it has
276
      contents</p>
277
         <p>This is a wrapper around the "header" template which ensures that
278
      some text is returned; if all else fails, the element name is
279
    used.</p>
280
         <param name="minimal">false</param>
281
      </desc>
282
   </doc>
283
  <xsl:template name="headerLink">
284
      <xsl:param name="minimal">false</xsl:param>
285
      <xsl:variable name="Text">
286
         <xsl:call-template name="header">
287
            <xsl:with-param name="minimal" select="$minimalCrossRef"/>
288
	           <xsl:with-param name="display">plain</xsl:with-param>
289
         </xsl:call-template>
290
      </xsl:variable>
291
      <xsl:choose>
292
         <xsl:when test="$Text=''">
293
	   <!--
294
	       <xsl:text>&lt;</xsl:text>
295
	       <xsl:value-of select="local-name(.)"/>
296
	       <xsl:text>&gt;</xsl:text>
297
	   -->
298
         </xsl:when>
299
         <xsl:otherwise>
300
            <xsl:copy-of select="$Text"/>
301
         </xsl:otherwise>
302
      </xsl:choose>
303
  </xsl:template>
304
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
305
      <desc>
306
         <p>[common] Make a hypertext link</p>
307
         <p>cross-referencing </p>
308
         <param name="ptr">ptr</param>
309
      </desc>
310
   </doc>
311
  <xsl:template name="makeTEILink">
312
      <xsl:param name="ptr" as="xs:boolean" select="false()"/>
313
      <!-- is this a ptr or a ref? -->
314

    
315
    <xsl:choose>
316
      <!-- If there is a target attribute starting with #, it is always a local reference -->
317
      <xsl:when test="@target and starts-with(@target,'#')">
318
            <xsl:call-template name="makeInternalLink">
319
               <xsl:with-param name="target" select="substring(@target,2)"/>
320
               <xsl:with-param name="ptr" select="$ptr"/>
321
               <xsl:with-param name="dest">
322
                  <xsl:call-template name="generateEndLink">
323
                     <xsl:with-param name="where">
324
                        <xsl:value-of select="substring(@target,2)"/>
325
                     </xsl:with-param>
326
                  </xsl:call-template>
327
               </xsl:with-param>
328
            </xsl:call-template>
329
         </xsl:when>
330
         <!-- if we are doing TEI P4, all targets are local -->
331
      <xsl:when test="@target and $teiP4Compat='true'">
332
            <xsl:call-template name="makeInternalLink">
333
               <xsl:with-param name="target" select="@target"/>
334
               <xsl:with-param name="ptr" select="$ptr"/>
335
               <xsl:with-param name="dest">
336
                  <xsl:call-template name="generateEndLink">
337
                     <xsl:with-param name="where">
338
                        <xsl:value-of select="@target"/>
339
                     </xsl:with-param>
340
                  </xsl:call-template>
341
               </xsl:with-param>
342
            </xsl:call-template>
343
         </xsl:when>
344
         <!-- other uses of target means it is external -->
345
      <xsl:when test="@target">
346
            <xsl:call-template name="makeExternalLink">
347
               <xsl:with-param name="ptr" select="$ptr"/>
348
               <xsl:with-param name="dest">
349
                  <xsl:value-of select="@target"/>
350
               </xsl:with-param>
351
            </xsl:call-template>
352
         </xsl:when>
353
         <!-- If there is a url attribute starting with #, it is a local
354
       reference -->
355
      <xsl:when test="@url and starts-with(@url,'#')">
356
            <xsl:call-template name="makeInternalLink">
357
               <xsl:with-param name="target" select="substring(@url,2)"/>
358
               <xsl:with-param name="ptr" select="$ptr"/>
359
               <xsl:with-param name="dest">
360
                  <xsl:call-template name="generateEndLink">
361
                     <xsl:with-param name="where">
362
                        <xsl:value-of select="substring(@url,2)"/>
363
                     </xsl:with-param>
364
                  </xsl:call-template>
365
               </xsl:with-param>
366
            </xsl:call-template>
367
         </xsl:when>
368
         <!-- otherwise it is an external URL -->
369
      <xsl:when test="@url">
370
            <xsl:call-template name="makeExternalLink">
371
               <xsl:with-param name="ptr" select="$ptr"/>
372
               <xsl:with-param name="dest">
373
                  <xsl:value-of select="@url"/>
374
               </xsl:with-param>
375
            </xsl:call-template>
376
         </xsl:when>
377
         <!-- A doc attribute means an external reference -->
378
      <xsl:when test="@doc">
379
            <xsl:call-template name="makeExternalLink">
380
               <xsl:with-param name="ptr" select="$ptr"/>
381
               <xsl:with-param name="dest">
382
                  <xsl:value-of select="unparsed-entity-uri(@doc)"/>
383
               </xsl:with-param>
384
            </xsl:call-template>
385
         </xsl:when>
386
         <xsl:otherwise>
387
        <!--
388
      <xsl:for-each select="@*">
389
	[[markup error: <xsl:value-of select="name(.)"/>=<xsl:value-of select="."/>]]
390
      </xsl:for-each>
391
-->
392
        <xsl:apply-templates/>
393
         </xsl:otherwise>
394
      </xsl:choose>
395
  </xsl:template>
396
</xsl:stylesheet>