~ubuntu-branches/debian/wheezy/jing-trang/wheezy

« back to all changes in this revision

Viewing changes to dtdinst/tei2rng.xsl

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Thibault
  • Date: 2009-09-01 15:53:03 UTC
  • Revision ID: james.westby@ubuntu.com-20090901155303-2kweef05h5v9j3ni
Tags: upstream-20090818
ImportĀ upstreamĀ versionĀ 20090818

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0"?>
 
2
<xsl:stylesheet version="1.0"
 
3
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
4
  xmlns:saxon="http://icl.com/saxon"
 
5
  extension-element-prefixes="saxon"
 
6
  xmlns:t="http://www.thaiopensource.com/ns/annotations"
 
7
  xmlns:a="http://relaxng.org/ns/compatibility/annotations/0.9"
 
8
  xmlns="http://relaxng.org/ns/structure/0.9">
 
9
 
 
10
<xsl:import href="dtdinst2rng.xsl"/>
 
11
 
 
12
<xsl:output indent="yes" encoding="iso-8859-1"/>
 
13
 
 
14
<xsl:param name="out-suffix" select="'.rng'"/>
 
15
<xsl:param name="element-prefix" select="''"/>
 
16
<xsl:param name="attlist-prefix" select="'al.'"/>
 
17
 
 
18
<xsl:key name="override" match="overridden[not(duplicate)]" use="*/@name"/>
 
19
 
 
20
<xsl:template match="doctype">
 
21
  <grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
 
22
    <xsl:apply-templates/>
 
23
  </grammar>
 
24
</xsl:template>
 
25
 
 
26
<xsl:template match="modelGroup|datatype">
 
27
  <define name="{@name}">
 
28
    <xsl:if test="key('override',@name)">
 
29
      <xsl:call-template name="condition"/>
 
30
    </xsl:if>
 
31
    <xsl:apply-templates/>
 
32
  </define>
 
33
</xsl:template>
 
34
 
 
35
<xsl:template match="attributeGroup">
 
36
  <define name="{@name}">
 
37
    <xsl:if test="not(*)">
 
38
      <empty/>
 
39
    </xsl:if>
 
40
    <xsl:apply-templates/>
 
41
  </define>
 
42
</xsl:template>
 
43
 
 
44
<xsl:template match="default|fixed|implied" mode="required">
 
45
  <xsl:param name="content"/>
 
46
  <optional>
 
47
    <xsl:for-each select="ancestor::attributeGroup">
 
48
      <xsl:if test="key('override',@name)">
 
49
        <xsl:call-template name="condition"/>
 
50
      </xsl:if>
 
51
    </xsl:for-each>
 
52
    <xsl:copy-of select="$content"/>
 
53
  </optional>
 
54
</xsl:template>
 
55
 
 
56
<xsl:template match="attributeDefaultRef[@name='INHERITED']"
 
57
              mode="default-value">
 
58
  <xsl:attribute name="t:inherited">true</xsl:attribute>
 
59
</xsl:template>
 
60
 
 
61
<xsl:template match="flag">
 
62
  <xsl:if test="starts-with(@name,'TEI.')
 
63
                and @name != 'TEI.2'
 
64
                and @name != 'TEI.general'
 
65
                and @name != 'TEI.singleBase'">
 
66
    <define name="{@name}">
 
67
      <xsl:apply-templates/>
 
68
    </define>
 
69
  </xsl:if>
 
70
</xsl:template>
 
71
 
 
72
<!-- Define the marked section keywords as ignore in teikey2. -->
 
73
<xsl:template match="overridden[flag[starts-with(@name,'TEI.') 
 
74
                                     and not(@name='TEI.XML')
 
75
                                     and not(@name='TEI.general')
 
76
                                     and ignore]]">
 
77
  <define name="{flag/@name}">
 
78
    <ref name="IGNORE"/>
 
79
  </define>
 
80
</xsl:template>
 
81
 
 
82
<xsl:template match="externalIdRef">
 
83
  <xsl:variable name="f"
 
84
      select="concat(key('param',@name)/@system,$out-suffix)"/>
 
85
  <include href="{$f}"/>
 
86
  <saxon:output href="{$f}">
 
87
    <grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
 
88
      <xsl:if test="$f = concat('tei2.dtd', $out-suffix)">
 
89
        <xsl:call-template name="main"/>
 
90
      </xsl:if>
 
91
      <xsl:if test="$f = concat('teikey2.ent', $out-suffix)">
 
92
        <xsl:call-template name="key"/>
 
93
      </xsl:if>
 
94
      <xsl:apply-templates/>
 
95
    </grammar>
 
96
  </saxon:output>
 
97
</xsl:template>
 
98
 
 
99
<xsl:template match="element">
 
100
  <xsl:variable name="name">
 
101
    <xsl:apply-templates select="*[1]"/>
 
102
  </xsl:variable>
 
103
  <define name="{$element-prefix}{$name}">
 
104
    <xsl:call-template name="condition"/>
 
105
    <element name="{$name}">
 
106
      <ref name="{$attlist-prefix}{$name}"/>
 
107
      <xsl:apply-templates select="*[2]"/>
 
108
    </element>
 
109
  </define>
 
110
</xsl:template>
 
111
 
 
112
<xsl:template name="condition">
 
113
  <xsl:variable name="flag"
 
114
    select="ancestor::includedSection[starts-with(@flag,'TEI.')
 
115
                                      and @flag != 'TEI.2'
 
116
                                      and @flag != 'TEI.mixed'
 
117
                                      and @flag != 'TEI.general'
 
118
                                      and @flag != 'TEI.singleBase'][1]/@flag"/>
 
119
  <xsl:if test="$flag">
 
120
    <ref name="{$flag}"/>
 
121
  </xsl:if>
 
122
</xsl:template>
 
123
 
 
124
<!-- This puts the definition of gram in the 'right' place (in the
 
125
dictonaries module. -->
 
126
 
 
127
<xsl:template match="ignoredSection[@flag='gram'][ancestor::externalIdRef[@name='TEI.dictionaries.dtd']]">
 
128
  <xsl:apply-templates select="//element[nameSpecRef[@name='n.gram']]"/>
 
129
  <xsl:apply-templates select="//attlist[nameSpecRef[@name='n.gram']]"/>
 
130
</xsl:template>
 
131
 
 
132
<!-- This makes things work when TEI.mixed is turned on. -->
 
133
 
 
134
<xsl:template match="ignoredSection[@flag='TEI.mixed'
 
135
                                    and contains(., 'component')]">
 
136
<xsl:text>
 
137
</xsl:text>
 
138
<xsl:comment>
 
139
  <xsl:value-of select="substring-before(substring-after(.,'&lt;!--'),'--&gt;')"/>
 
140
</xsl:comment>
 
141
<define name="component" combine="choice">
 
142
  <ref name="TEI.mixed"/>
 
143
  <xsl:apply-templates select="key('param','component')/*"/>
 
144
</define>
 
145
</xsl:template>
 
146
 
 
147
<xsl:template name="main">
 
148
  <start>
 
149
    <choice>
 
150
      <ref name="TEI.2"/>
 
151
      <ref name="teiCorpus.2"/>
 
152
    </choice>
 
153
  </start>
 
154
  <define name="TEI...end"><notAllowed/></define>
 
155
  <define name="dictScrap"><notAllowed/></define>
 
156
  <define name="att" combine="choice"><notAllowed/></define>
 
157
  <define name="gi" combine="choice"><notAllowed/></define>
 
158
  <define name="tag" combine="choice"><notAllowed/></define>
 
159
  <define name="val" combine="choice"><notAllowed/></define>
 
160
</xsl:template>
 
161
 
 
162
<xsl:template name="key">
 
163
  <define name="IGNORE"><notAllowed/></define>
 
164
  <define name="INCLUDE"><empty/></define>
 
165
</xsl:template>
 
166
 
 
167
<xsl:template match="include">
 
168
  <ref name="INCLUDE"/>
 
169
</xsl:template>
 
170
 
 
171
<xsl:template match="ignore">
 
172
  <ref name="IGNORE"/>
 
173
</xsl:template>
 
174
 
 
175
</xsl:stylesheet>