File: schema2dtd.xsl

package info (click to toggle)
fop 1%3A1.0.dfsg2-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 31,400 kB
  • sloc: java: 136,827; xml: 104,947; sh: 386; python: 316; makefile: 46
file content (335 lines) | stat: -rw-r--r-- 12,877 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- $Id: schema2dtd.xsl 426576 2006-07-28 15:44:37Z jeremias $ -->
<xsl:stylesheet saxon:trace="no"
    version="1.1"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:saxon="http://icl.com/saxon"
    xmlns:xs = "http://www.w3.org/2001/XMLSchema"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:math="http://exslt.org/math"
    extension-element-prefixes="saxon date math"
    exclude-result-prefixes="fo">

<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/xs:schema">
<xsl:text>
</xsl:text>
<xsl:comment>
 This DTD has been developed in order to validate XSL FO documents
 The namespace prefix is xmlns:fo="http://www.w3.org/1999/XSL/Format".

 In addition, the functionality implemented or not in FOP has been segregated
 To create an FOP only validating DTD, remove the references marked %\([a-zA-Z_]+\)_Not;
 I certainly have not exhaustively removed all of the properties not implemented in FOP.
 If you notice an item that is incorrectly included or excluded, please send me a note

 The FOP only DTD will not guard against the entering of attribute values not implemented by FOP
 (Such as fo:leader-pattern="use-content")
 See http://xml.apache.org/fop/implemented.html for more detailed restrictions

 It has not been well tested.
 For instance, the length attribute is able to be negative for some elements like margins.
 I have not represented that here.
 I have not added values for the Aural properties
 There are several instances where I've entered %integer_Type; and it should be positive-integer or number
 The DTD trys to handle the text based rules re: fo:markers, fo:float, footer and fo:initial-property-set
 But, allows you to do illegal things if you want because I couldn't figure out how to constrain against the illegal actions.

 Please e-mail your comments to cpaussa@myrealbox.com

</xsl:comment><xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text><xsl:comment> Entity definitions for groups of formatting objects             </xsl:comment><xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text>
  <xsl:apply-templates select="./xs:simpleType"/>
<xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text><xsl:comment> Attribute Groups                                                </xsl:comment><xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment>
  <xsl:apply-templates select="./xs:attributeGroup"/>
<xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text><xsl:comment> Element Groups                                                  </xsl:comment><xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text>
  <xsl:apply-templates select="./xs:group"/>
<xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text><xsl:comment> Elements                                                        </xsl:comment><xsl:text>
</xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
</xsl:text>
  <xsl:apply-templates select="./xs:element"/>
</xsl:template>

<xsl:template match="xs:group">
  <xsl:text disable-output-escaping="yes">
&lt;!ENTITY % </xsl:text><xsl:value-of select="./@name"/><xsl:text> "</xsl:text>
  <xsl:for-each select="./xs:choice/xs:element">
    <xsl:text>
  </xsl:text>
    <xsl:value-of select="./@ref"/>
    <xsl:if test="position() != last()">
      <xsl:text> |</xsl:text>
    </xsl:if>
  </xsl:for-each>
  <xsl:if test="./xs:choice/xs:group">
    <xsl:variable name="ref1">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./xs:choice/xs:group[1]/@ref"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="ref2">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./xs:choice/xs:group[2]/@ref"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:text>
  %</xsl:text>
    <xsl:value-of select="$ref1"/>
    <xsl:text>;</xsl:text>
    <xsl:if test="(/xs:schema/xs:group[@name = $ref1]/xs:choice/xs:element) and (/xs:schema/xs:group[@name = $ref2]/xs:choice/xs:element)">
      <xsl:text>| </xsl:text>
    </xsl:if>
    <xsl:text>
  %</xsl:text>
    <xsl:value-of select="$ref2"/><xsl:text>;</xsl:text>
  </xsl:if>
  <xsl:text disable-output-escaping="yes">
"&gt;</xsl:text>
</xsl:template>

<xsl:template match="xs:attributeGroup">
  <xsl:text disable-output-escaping="yes">
&lt;!ENTITY % </xsl:text><xsl:value-of select="./@name"/><xsl:text> "</xsl:text>
  <xsl:for-each select="./xs:attribute">
    <xsl:variable name="name">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./@name"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="type">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./@type"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:text>
  </xsl:text>
    <xsl:value-of select="$name"/>
    <xsl:choose>
      <xsl:when test="$type = 'xs:string'">
        <xsl:text> CDATA</xsl:text>
      </xsl:when>
      <xsl:when test="/xs:schema/xs:simpleType[@name = $type]/xs:restriction/xs:enumeration">
        <!--This item is a directly enumerated type-->
        <xsl:text> (%</xsl:text>
        <xsl:value-of select="$type"/>
        <xsl:text>;)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text> CDATA</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> #IMPLIED</xsl:text>
  </xsl:for-each>
  <xsl:for-each select="./xs:attributeGroup">
    <xsl:variable name="ref">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./@ref"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:text>
  %</xsl:text><xsl:value-of select="$ref"/><xsl:text>;</xsl:text>
  </xsl:for-each>
  <xsl:text disable-output-escaping="yes">
  "&gt;</xsl:text>
</xsl:template>

<xsl:template match="xs:simpleType">
  <xsl:if test="./xs:restriction/xs:enumeration">
    <xsl:text disable-output-escaping="yes">
&lt;!ENTITY % </xsl:text><xsl:value-of select="./@name"/><xsl:text> "</xsl:text>
    <xsl:for-each select="./xs:restriction/xs:enumeration">
      <xsl:value-of select="./@value"/>
      <xsl:if test="position() != last()">
        <xsl:text>|</xsl:text>
      </xsl:if>
    </xsl:for-each>
    <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
  </xsl:if>
</xsl:template>

<xsl:template match="xs:element">
  <xsl:text disable-output-escaping="yes">&lt;!ELEMENT fo:</xsl:text>
  <xsl:value-of select="./@name"/>
  <xsl:choose>
    <xsl:when test="( not(./xs:complexType/xs:sequence) and not(./xs:complexType/xs:choice) )">
      <xsl:text> EMPTY</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text> (</xsl:text>
      <xsl:if test="./xs:complexType/@mixed = 'true'">
        <xsl:text>#PCDATA|</xsl:text>
      </xsl:if>
      <xsl:for-each select="./xs:complexType/xs:sequence">
        <xsl:for-each select="./xs:element">
          <xsl:value-of select="./@ref"/>
          <xsl:call-template name="addPlus"/>
          <xsl:if test="position() != last()">
            <xsl:text>,</xsl:text>
          </xsl:if>
        </xsl:for-each>
        <xsl:for-each select="./xs:group">
          <xsl:text>%</xsl:text>
          <xsl:variable name="ref">
            <xsl:call-template name="strip_fo">
              <xsl:with-param name="ref" select="./@ref"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:value-of select="$ref"/>
          <xsl:text>;</xsl:text>
          <xsl:call-template name="addPlus"/>
          <xsl:if test="position() != last()">
            <xsl:text>,</xsl:text>
          </xsl:if>
        </xsl:for-each>
      </xsl:for-each>
      <xsl:for-each select="./xs:complexType/xs:choice">
        <xsl:for-each select="./xs:element">
          <xsl:value-of select="./@ref"/>
          <xsl:call-template name="addPlus"/>
          <xsl:if test="position() != last()">
            <xsl:text>|</xsl:text>
          </xsl:if>
        </xsl:for-each>
        <xsl:for-each select="./xs:group">
          <xsl:text>%</xsl:text>
          <xsl:variable name="ref">
            <xsl:call-template name="strip_fo">
              <xsl:with-param name="ref" select="./@ref"/>
            </xsl:call-template>
          </xsl:variable>
          <xsl:value-of select="$ref"/>
          <xsl:text>;</xsl:text>
          <xsl:call-template name="addPlus"/>
          <xsl:if test="position() != last()">
            <xsl:text>|</xsl:text>
          </xsl:if>
        </xsl:for-each>
      </xsl:for-each>
      <xsl:text>)</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:for-each select="./xs:complexType/xs:sequence">
    <xsl:call-template name="addPlus"/>
  </xsl:for-each>
  <xsl:for-each select="./xs:complexType/xs:choice">
    <xsl:call-template name="addPlus"/>
  </xsl:for-each>
  <xsl:text disable-output-escaping="yes">&gt;
&lt;!ATTLIST fo:</xsl:text>
  <xsl:value-of select="./@name"/>
  <xsl:for-each select="./xs:complexType/xs:attribute">
    <xsl:variable name="name">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./@name"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="type">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./@type"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:text>
  </xsl:text>
    <xsl:value-of select="$name"/>
    <xsl:choose>
      <xsl:when test="$type = 'xs:string'">
        <xsl:text> CDATA</xsl:text>
      </xsl:when>
      <xsl:when test="/xs:schema/xs:simpleType[@name = $type]/xs:restriction/xs:enumeration">
        <!--This item is a directly enumerated type-->
        <xsl:text> (%</xsl:text>
        <xsl:value-of select="$type"/>
        <xsl:text>;)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text> CDATA</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="@use = 'required'">
        <xsl:text> #REQUIRED</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text> #IMPLIED</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
  <xsl:for-each select="./xs:complexType/xs:attributeGroup">
    <xsl:variable name="ref">
      <xsl:call-template name="strip_fo">
        <xsl:with-param name="ref" select="./@ref"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:text>
  %</xsl:text>
    <xsl:value-of select="$ref"/>
    <xsl:text>;</xsl:text>
  </xsl:for-each>
  <xsl:text disable-output-escaping="yes">
&gt;
</xsl:text>
</xsl:template>

<xsl:template name="addPlus">
  <xsl:choose>
    <xsl:when test="(@minOccurs = 0) and (@maxOccurs = 'unbounded')">
      <xsl:text>*</xsl:text>
    </xsl:when>
    <xsl:when test="(@minOccurs = 0) and ((@maxOccurs = 1) or not(@maxOccurs))">
      <xsl:text>?</xsl:text>
    </xsl:when>
    <xsl:when test="((@minOccurs = 1) or not(@minOccurs)) and (@maxOccurs = 'unbounded')">
      <xsl:text>+</xsl:text>
    </xsl:when>
    <xsl:when test="not(@minOccurs) and not(@maxOccurs)">
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>!error!</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="strip_fo">
  <xsl:param name="ref"/>
  <xsl:choose>
    <xsl:when test="substring($ref,1,3) = 'fo:'">
      <xsl:value-of select="substring($ref,4)"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$ref"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>