Statistics
| Revision:

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

History | View | Annotate | Download (10.8 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cals="http://www.oasis-open.org/specs/tm9901" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:iso="http://www.iso.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0" version="2.0" exclude-result-prefixes="cals ve o r m v wp w10 w wne mml tbx iso tei a xs pic fn">
3
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
4
    <desc>
5
      <p> TEI Utility stylesheet defining templates for use in
6
      processing ODD</p>
7

    
8
      <p>This software is dual-licensed:
9

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

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

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

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

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

    
28
This software is provided by the copyright holders and contributors
29
"as is" and any express or implied warranties, including, but not
30
limited to, the implied warranties of merchantability and fitness for
31
a particular purpose are disclaimed. In no event shall the copyright
32
holder or contributors be liable for any direct, indirect, incidental,
33
special, exemplary, or consequential damages (including, but not
34
limited to, procurement of substitute goods or services; loss of use,
35
data, or profits; or business interruption) however caused and on any
36
theory of liability, whether in contract, strict liability, or tort
37
(including negligence or otherwise) arising in any way out of the use
38
of this software, even if advised of the possibility of such damage.
39
</p>
40
      <p>Author: See AUTHORS</p>
41
      <p>Id: $Id: functions.xsl 9464 2011-10-06 08:27:01Z rahtz $</p>
42
      <p>Copyright: 2008, TEI Consortium</p>
43
    </desc>
44
  </doc>
45
  <xsl:template name="makeDescription">
46
    <xsl:param name="includeValList">false</xsl:param>
47
    <xsl:param name="coded">true</xsl:param>
48
    <xsl:param name="showListRef">true</xsl:param>
49
    <xsl:variable name="documentationLanguage">
50
      <xsl:call-template name="generateDoc"/>
51
    </xsl:variable>
52
    <xsl:variable name="langs">
53
      <xsl:value-of select="concat(normalize-space($documentationLanguage),' ')"/>
54
    </xsl:variable>
55
    <xsl:variable name="firstLang">
56
      <xsl:value-of select="substring-before($langs,' ')"/>
57
    </xsl:variable>
58
    <!-- first the gloss -->
59
    <xsl:call-template name="makeGloss">
60
      <xsl:with-param name="langs" select="$langs"/>
61
    </xsl:call-template>
62
    <!-- now the description -->
63
    <xsl:choose>
64
      <xsl:when test="not(tei:desc)"> </xsl:when>
65
      <xsl:when test="count(tei:desc)=1">
66
        <xsl:for-each select="tei:desc">
67
          <xsl:apply-templates select="." mode="inLanguage"/>
68
        </xsl:for-each>
69
      </xsl:when>
70
      <xsl:when test="tei:desc[@xml:lang=$firstLang]">
71
        <xsl:for-each select="tei:desc[@xml:lang=$firstLang]">
72
          <xsl:apply-templates select="." mode="inLanguage"/>
73
        </xsl:for-each>
74
      </xsl:when>
75
      <xsl:otherwise>
76
        <xsl:variable name="D">
77
          <xsl:for-each select="tei:desc">
78
            <xsl:variable name="currentLang">
79
              <xsl:call-template name="findLanguage"/>
80
            </xsl:variable>
81
            <xsl:if test="contains($langs,concat($currentLang,' '))">
82
              <xsl:apply-templates select="." mode="inLanguage"/>
83
            </xsl:if>
84
          </xsl:for-each>
85
        </xsl:variable>
86
        <xsl:choose>
87
          <xsl:when test="$D='' and tei:desc[not(@xml:lang)]">
88
            <xsl:for-each select="tei:desc[not(@xml:lang)]">
89
              <xsl:apply-templates select="." mode="inLanguage"/>
90
            </xsl:for-each>
91
          </xsl:when>
92
          <xsl:when test="$coded='false'">
93
            <xsl:value-of select="$D"/>
94
          </xsl:when>
95
          <xsl:otherwise>
96
            <xsl:copy-of select="$D"/>
97
          </xsl:otherwise>
98
        </xsl:choose>
99
      </xsl:otherwise>
100
    </xsl:choose>
101
    <xsl:choose>
102
      <xsl:when test="$includeValList='false'"/>
103
      <xsl:when test="tei:valList[@type='open']">
104
        <xsl:text>&#10;</xsl:text>
105
        <xsl:call-template name="i18n">
106
          <xsl:with-param name="word">
107
            <xsl:text>Sample values include</xsl:text>
108
          </xsl:with-param>
109
        </xsl:call-template>
110
        <xsl:text>: </xsl:text>
111
        <xsl:for-each select="tei:valList/tei:valItem">
112
          <xsl:number/>
113
          <xsl:text>] </xsl:text>
114
          <xsl:choose>
115
            <xsl:when test="tei:altIdent=@ident">
116
              <xsl:value-of select="@ident"/>
117
            </xsl:when>
118
            <xsl:when test="tei:altIdent">
119
              <xsl:value-of select="normalize-space(tei:altIdent)"/>
120
            </xsl:when>
121
            <xsl:otherwise>
122
              <xsl:value-of select="@ident"/>
123
            </xsl:otherwise>
124
          </xsl:choose>
125
          <xsl:variable name="documentationLanguage">
126
            <xsl:call-template name="generateDoc"/>
127
          </xsl:variable>
128
          <xsl:variable name="langs">
129
            <xsl:value-of select="concat(normalize-space($documentationLanguage),' ')"/>
130
          </xsl:variable>
131
          <xsl:variable name="firstLang">
132
            <xsl:value-of select="substring-before($langs,' ')"/>
133
          </xsl:variable>
134
          <xsl:call-template name="makeGloss">
135
            <xsl:with-param name="langs" select="$langs"/>
136
          </xsl:call-template>
137
          <xsl:if test="following-sibling::tei:valItem">
138
            <xsl:text>; </xsl:text>
139
          </xsl:if>
140
        </xsl:for-each>
141
      </xsl:when>
142
      <xsl:when test="tei:valList[@type='semi']">
143
        <xsl:text>&#10;</xsl:text>
144
        <xsl:call-template name="i18n">
145
          <xsl:with-param name="word">
146
            <xsl:text>Suggested values include</xsl:text>
147
          </xsl:with-param>
148
        </xsl:call-template>
149
        <xsl:text>: </xsl:text>
150
        <xsl:for-each select="tei:valList/tei:valItem">
151
          <xsl:number/>
152
          <xsl:text>] </xsl:text>
153
          <xsl:choose>
154
            <xsl:when test="tei:altIdent=@ident">
155
              <xsl:value-of select="@ident"/>
156
            </xsl:when>
157
            <xsl:when test="tei:altIdent">
158
              <xsl:value-of select="normalize-space(tei:altIdent)"/>
159
            </xsl:when>
160
            <xsl:otherwise>
161
              <xsl:value-of select="@ident"/>
162
            </xsl:otherwise>
163
          </xsl:choose>
164
          <xsl:variable name="documentationLanguage">
165
            <xsl:call-template name="generateDoc"/>
166
          </xsl:variable>
167
          <xsl:variable name="langs">
168
            <xsl:value-of select="concat(normalize-space($documentationLanguage),' ')"/>
169
          </xsl:variable>
170
          <xsl:variable name="firstLang">
171
            <xsl:value-of select="substring-before($langs,' ')"/>
172
          </xsl:variable>
173
          <xsl:call-template name="makeGloss">
174
            <xsl:with-param name="langs" select="$langs"/>
175
          </xsl:call-template>
176
          <xsl:if test="following-sibling::tei:valItem">
177
            <xsl:text>; </xsl:text>
178
          </xsl:if>
179
        </xsl:for-each>
180
      </xsl:when>
181
    </xsl:choose>
182
    <xsl:if test="tei:listRef and $showListRef='true'">
183
	<xsl:text> [</xsl:text>
184
	<xsl:for-each select="tei:listRef/tei:*">
185
	  <xsl:apply-templates select="." mode="weave"/>
186
	  <xsl:if test="following-sibling::tei:*"> 
187
	    <xsl:text> </xsl:text>
188
	  </xsl:if>
189
	</xsl:for-each>
190
	<xsl:text>]</xsl:text>
191
    </xsl:if>
192
  </xsl:template>
193

    
194
  <xsl:template name="makeGloss">
195
    <xsl:param name="langs"/>
196
    <xsl:variable name="firstLang">
197
      <xsl:value-of select="substring-before($langs,' ')"/>
198
    </xsl:variable>
199
    <xsl:choose>
200
      <xsl:when test="not(tei:gloss)"/>
201
      <xsl:when test="string-length(tei:gloss[1])=0"/>
202
      <xsl:when test="count(tei:gloss)=1 and not(tei:gloss[@xml:lang])">
203
        <xsl:text> (</xsl:text>
204
        <xsl:apply-templates select="tei:gloss" mode="inLanguage"/>
205
        <xsl:text>) </xsl:text>
206
      </xsl:when>
207
      <xsl:when test="tei:gloss[@xml:lang=$firstLang]">
208
        <xsl:if test="not(tei:gloss[@xml:lang=$firstLang]='')">
209
          <xsl:text> (</xsl:text>
210
          <xsl:apply-templates select="tei:gloss[@xml:lang=$firstLang]" mode="inLanguage"/>
211
          <xsl:text>) </xsl:text>
212
        </xsl:if>
213
      </xsl:when>
214
      <xsl:otherwise>
215
        <xsl:variable name="G">
216
          <xsl:for-each select="tei:gloss">
217
            <xsl:variable name="currentLang">
218
              <xsl:call-template name="findLanguage"/>
219
            </xsl:variable>
220
            <xsl:if test="contains($langs,concat($currentLang,' '))">
221
              <xsl:text>(</xsl:text>
222
              <xsl:apply-templates select="." mode="inLanguage"/>
223
              <xsl:text>) </xsl:text>
224
            </xsl:if>
225
          </xsl:for-each>
226
        </xsl:variable>
227
        <xsl:choose>
228
          <xsl:when test="$G='' and tei:gloss[not(@xml:lang)]">
229
            <xsl:text> (</xsl:text>
230
            <xsl:apply-templates select="tei:gloss[not(@xml:lang)]" mode="inLanguage"/>
231
            <xsl:text>) </xsl:text>
232
          </xsl:when>
233
          <xsl:otherwise>
234
            <xsl:copy-of select="$G"/>
235
          </xsl:otherwise>
236
        </xsl:choose>
237
      </xsl:otherwise>
238
    </xsl:choose>
239
  </xsl:template>
240

    
241
  <xsl:template name="findLanguage">
242
    <xsl:choose>
243
      <xsl:when test="@xml:lang">
244
        <xsl:value-of select="@xml:lang"/>
245
      </xsl:when>
246
      <xsl:when test="ancestor::tei:*[@xml:lang]">
247
        <xsl:value-of select="(ancestor::tei:*[@xml:lang])[1]/@xml:lang"/>
248
      </xsl:when>
249
      <xsl:otherwise>
250
        <xsl:text>en</xsl:text>
251
      </xsl:otherwise>
252
    </xsl:choose>
253
  </xsl:template>
254

    
255
</xsl:stylesheet>