Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / odds2 / odd2json.xsl @ 187

History | View | Annotate | Download (9.2 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet 
3
    xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
4
    xmlns:fo="http://www.w3.org/1999/XSL/Format" 
5
    xmlns:html="http://www.w3.org/1999/xhtml" 
6
    xmlns:i="http://www.iso.org/ns/1.0"
7
    xmlns:rng="http://relaxng.org/ns/structure/1.0"
8
    xmlns:s="http://www.ascc.net/xml/schematron" 
9
    xmlns:sch="http://purl.oclc.org/dsdl/schematron" 
10
    xmlns="http://www.tei-c.org/ns/1.0"
11
    xmlns:tei="http://www.tei-c.org/ns/1.0"
12
    xmlns:teix="http://www.tei-c.org/ns/Examples" 
13
    xmlns:xi="http://www.w3.org/2001/XInclude"
14
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
15
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16
    exclude-result-prefixes="a fo html i rng s sch tei teix xi xs xsl" 
17
    version="2.0">
18
  <xsl:import href="teiodds.xsl"/>
19
  <xsl:import href="../common2/i18n.xsl"/>
20
  <xsl:import href="../common2/tei-param.xsl"/>
21
  <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
22
      <desc>
23
         <p> TEI stylesheet for making JSON from ODD </p>
24
         <p>This software is dual-licensed:
25

    
26
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
27
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
28

    
29
2. http://www.opensource.org/licenses/BSD-2-Clause
30
		
31
All rights reserved.
32

    
33
Redistribution and use in source and binary forms, with or without
34
modification, are permitted provided that the following conditions are
35
met:
36

    
37
* Redistributions of source code must retain the above copyright
38
notice, this list of conditions and the following disclaimer.
39

    
40
* Redistributions in binary form must reproduce the above copyright
41
notice, this list of conditions and the following disclaimer in the
42
documentation and/or other materials provided with the distribution.
43

    
44
This software is provided by the copyright holders and contributors
45
"as is" and any express or implied warranties, including, but not
46
limited to, the implied warranties of merchantability and fitness for
47
a particular purpose are disclaimed. In no event shall the copyright
48
holder or contributors be liable for any direct, indirect, incidental,
49
special, exemplary, or consequential damages (including, but not
50
limited to, procurement of substitute goods or services; loss of use,
51
data, or profits; or business interruption) however caused and on any
52
theory of liability, whether in contract, strict liability, or tort
53
(including negligence or otherwise) arising in any way out of the use
54
of this software, even if advised of the possibility of such damage.
55
</p>
56
         <p>Author: See AUTHORS</p>
57
         <p>Id: $Id: odd2json.xsl 9669 2011-11-07 19:17:54Z rahtz $</p>
58
         <p>Copyright: 2011, TEI Consortium</p>
59
      </desc>
60
   </doc>
61
  <xsl:output encoding="utf-8" indent="yes" method="text"/>
62
  <xsl:strip-space elements="*"/>
63
  <xsl:param name="TEIC">false</xsl:param>
64
  <xsl:param name="verbose"/>
65
  <xsl:param name="outputDir"/>
66
  <xsl:param name="appendixWords"/>
67
  <xsl:template name="makeAnchor">
68
      <xsl:param name="name"/>
69
  </xsl:template>
70
  <xsl:param name="splitLevel">-1</xsl:param>
71
  <xsl:variable name="oddmode">dtd</xsl:variable>
72
  <xsl:variable name="filesuffix"/>
73
   <!-- get list of output files -->
74
  <xsl:variable name="linkColor"/>
75
  <xsl:template match="tei:moduleSpec[@type='decls']"/>
76

    
77
  <xsl:variable name="dq">"</xsl:variable>
78
  <xsl:variable name="escdq">\\"</xsl:variable>
79
  <xsl:template match="/">
80
    <xsl:text>{"title": "</xsl:text>
81
    <xsl:call-template name="generateTitle"/>
82
    <xsl:text>","edition": "</xsl:text>
83
    <xsl:call-template name="generateEdition"/>
84
    <xsl:text>","generator": "oddj2son",
85
    "date":"</xsl:text>
86
    <xsl:call-template name="showDate"/>
87
    <xsl:text>","modules": [</xsl:text>
88
    <xsl:for-each select="key('Modules',1)">
89
      <xsl:sort select="@ident"/>
90
      <xsl:text>{"ident":"</xsl:text>
91
      <xsl:value-of select="@ident"/>
92
      <xsl:text>",</xsl:text>
93
      <xsl:call-template name="desc"/>
94
      <xsl:text>}</xsl:text>
95
      <xsl:if test="not(position() = last())">,</xsl:if>
96
      <xsl:text>&#10;</xsl:text>
97
    </xsl:for-each>
98
    <xsl:text>],</xsl:text>
99

    
100
    <xsl:text>"elements": [</xsl:text>
101
    <xsl:for-each select="key('ELEMENTDOCS',1)">
102
      <xsl:sort select="@ident"/>
103
      <xsl:text>{"ident":"</xsl:text>
104
      <xsl:value-of select="@ident"/>
105
      <xsl:text>",</xsl:text>
106
      <xsl:text>"module":"</xsl:text>
107
      <xsl:value-of select="@module"/>
108
      <xsl:text>",</xsl:text>
109
      <xsl:call-template name="desc"/>
110
      <xsl:if test="tei:classes">
111
	<xsl:text>,"classes":[</xsl:text>
112
	<xsl:for-each select="tei:classes/tei:memberOf">
113
	  <xsl:text>{"</xsl:text>
114
	  <xsl:value-of select="@key"/>
115
	  <xsl:text>":"</xsl:text>
116
	  <xsl:for-each select="key('IDENTS',@key)">
117
	    <xsl:value-of select="@type"/>
118
	  </xsl:for-each>
119
	  <xsl:text>"}</xsl:text>
120
	  <xsl:if test="following-sibling::tei:memberOf">,</xsl:if>
121
	</xsl:for-each>
122
	<xsl:text>]</xsl:text>
123
      </xsl:if>
124
      <xsl:text>,"attributes":[</xsl:text>
125
      <xsl:variable name="a">
126
	<xsl:call-template name="atts"/>
127
      </xsl:variable>
128
      <xsl:for-each select="$a/tei:attDef">
129
	<xsl:text>{"ident":"</xsl:text>
130
	<xsl:value-of select="@ident"/>
131
	<xsl:text>",</xsl:text>
132
	<xsl:value-of select="tei:desc"/>
133
	<xsl:text>}</xsl:text>
134
	<xsl:if test="following-sibling::tei:attDef">,</xsl:if>
135
      </xsl:for-each>
136
      <xsl:text>]</xsl:text>
137
      <xsl:text>}</xsl:text>
138
      <xsl:if test="not(position() = last())">,</xsl:if>
139
      <xsl:text>&#10;</xsl:text>
140
    </xsl:for-each>
141
    <xsl:text>],</xsl:text>
142

    
143
    <xsl:text>"attclasses": [</xsl:text>
144
    <xsl:for-each select="key('ATTCLASSDOCS',1)">
145
      <xsl:sort select="@ident"/>
146
      <xsl:text>{"ident":"</xsl:text>
147
      <xsl:value-of  select="@ident"/>
148
      <xsl:text>",</xsl:text>
149
      <xsl:text>"type":"</xsl:text>
150
      <xsl:value-of  select="@type"/>
151
      <xsl:text>",</xsl:text>
152
      <xsl:call-template name="desc"/>
153
      <xsl:text>}</xsl:text>
154
      <xsl:if test="not(position() = last())">,</xsl:if>
155
      <xsl:text>&#10;</xsl:text>
156
    </xsl:for-each>
157
    <xsl:text>],</xsl:text>
158

    
159
    <xsl:text>"modelclasses": [</xsl:text>
160
    <xsl:for-each select="key('MODELCLASSDOCS',1)">
161
      <xsl:sort select="@ident"/>
162
      <xsl:text>{"ident":"</xsl:text>
163
      <xsl:value-of  select="@ident"/>
164
      <xsl:text>",</xsl:text>
165
      <xsl:text>"type":"</xsl:text>
166
      <xsl:value-of  select="@type"/>
167
      <xsl:text>",</xsl:text>
168
      <xsl:call-template name="desc"/>
169
      <xsl:text>}</xsl:text>
170
      <xsl:if test="not(position() = last())">,</xsl:if>
171
      <xsl:text>&#10;</xsl:text>
172
    </xsl:for-each>
173
    <xsl:text>],</xsl:text>
174

    
175
    <xsl:text>"macros": [</xsl:text>
176
    <xsl:for-each select="key('MACRODOCS',1)">
177
      <xsl:sort select="@ident"/>
178
      <xsl:text>{"ident":"</xsl:text>
179
      <xsl:value-of select="@ident"/>
180
      <xsl:text>",</xsl:text>
181
      <xsl:text>"type":"</xsl:text>
182
      <xsl:value-of select="@type"/>
183
      <xsl:text>",</xsl:text>
184
      <xsl:call-template name="desc"/>
185
      <xsl:text>}</xsl:text>
186
      <xsl:if test="not(position() = last())">,</xsl:if>
187
      <xsl:text>&#10;</xsl:text>
188
    </xsl:for-each>
189
    <xsl:text>]</xsl:text>
190
    <xsl:text>}</xsl:text>
191
  </xsl:template>
192

    
193
  <xsl:template name="bitOut">
194
      <xsl:param name="grammar"/>
195
      <xsl:param name="element"/>
196
      <xsl:param name="content"/>
197
      <xsl:value-of select="normalize-space($content)"/>
198
  </xsl:template>
199

    
200
  <xsl:template name="typewriter">
201
    <xsl:param name="text"/>
202
    <xsl:value-of select="$text"/>
203
  </xsl:template>
204

    
205
  <xsl:template name="desc">
206
    <xsl:variable name="d">      
207
      <xsl:call-template name="makeDescription"/>
208
    </xsl:variable>
209
    <xsl:text>"desc":"</xsl:text>
210
    <xsl:value-of select="replace(normalize-space($d),$dq,$escdq)"/>
211
    <xsl:text>"</xsl:text>
212
  </xsl:template>
213

    
214
  <xsl:template name="atts">
215
    <xsl:call-template name="listAtts"/>
216
    <xsl:if test="$TEIC='true'">
217
      <xsl:call-template name="classA">
218
	<xsl:with-param name="i">att.global</xsl:with-param>
219
      </xsl:call-template>
220
    </xsl:if>
221
    <xsl:for-each select="tei:classes/tei:memberOf">
222
      <xsl:call-template name="classA">
223
	<xsl:with-param name="i" select="@key"/>
224
      </xsl:call-template>
225
    </xsl:for-each>
226
  </xsl:template>
227

    
228
  <xsl:template name="listAtts">
229
    <xsl:for-each select=".//tei:attDef">
230
      <tei:attDef ident="{@ident}">
231
	<desc>
232
	  <xsl:call-template name="desc"/>
233
	</desc>
234
      </tei:attDef>
235
    </xsl:for-each>
236
  </xsl:template>
237

    
238
  <xsl:template name="classA">
239
    <xsl:param name="i"/>
240
    <xsl:for-each select="key('CLASSES',$i)">
241
      <xsl:call-template name="listAtts"/>
242
      <xsl:for-each select="tei:classes/tei:memberOf">
243
	<xsl:call-template name="classA">
244
	  <xsl:with-param name="i" select="@key"/>
245
	</xsl:call-template>
246
      </xsl:for-each>
247
    </xsl:for-each>
248
  </xsl:template>
249

    
250

    
251
    <xsl:template name="generateEdition">
252
      <xsl:value-of
253
	  select="tei:TEI/tei:teiHeader/tei:fileDesc/tei:editionStmt/tei:edition"/>
254
    </xsl:template>
255

    
256
    <xsl:template name="generateTitle">
257
      <xsl:for-each
258
	  select="tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt">
259
	<xsl:choose>
260
	  <xsl:when test="tei:title[@type='main']">
261
	    <xsl:apply-templates select="tei:title"/>
262
	  </xsl:when>
263
	  <xsl:otherwise>
264
	    <xsl:apply-templates select="tei:title"/>
265
	  </xsl:otherwise>
266
	</xsl:choose>
267
      </xsl:for-each>
268
    </xsl:template>
269

    
270
</xsl:stylesheet>