You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

schema2dtd.xsl 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- $Id$ -->
  17. <xsl:stylesheet saxon:trace="no"
  18. version="1.1"
  19. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20. xmlns:saxon="http://icl.com/saxon"
  21. xmlns:xs = "http://www.w3.org/2001/XMLSchema"
  22. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  23. xmlns:date="http://exslt.org/dates-and-times"
  24. xmlns:math="http://exslt.org/math"
  25. extension-element-prefixes="saxon date math"
  26. exclude-result-prefixes="fo">
  27. <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
  28. <xsl:strip-space elements="*"/>
  29. <xsl:template match="/xs:schema">
  30. <xsl:text>
  31. </xsl:text>
  32. <xsl:comment>
  33. This DTD has been developed in order to validate XSL FO documents
  34. The namespace prefix is xmlns:fo="http://www.w3.org/1999/XSL/Format".
  35. In addition, the functionality implemented or not in FOP has been segregated
  36. To create an FOP only validating DTD, remove the references marked %\([a-zA-Z_]+\)_Not;
  37. I certainly have not exhaustively removed all of the properties not implemented in FOP.
  38. If you notice an item that is incorrectly included or excluded, please send me a note
  39. The FOP only DTD will not guard against the entering of attribute values not implemented by FOP
  40. (Such as fo:leader-pattern="use-content")
  41. See http://xml.apache.org/fop/implemented.html for more detailed restrictions
  42. It has not been well tested.
  43. For instance, the length attribute is able to be negative for some elements like margins.
  44. I have not represented that here.
  45. I have not added values for the Aural properties
  46. There are several instances where I've entered %integer_Type; and it should be positive-integer or number
  47. The DTD trys to handle the text based rules re: fo:markers, fo:float, footer and fo:initial-property-set
  48. But, allows you to do illegal things if you want because I couldn't figure out how to constrain against the illegal actions.
  49. Please e-mail your comments to cpaussa@myrealbox.com
  50. </xsl:comment><xsl:text>
  51. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  52. </xsl:text><xsl:comment> Entity definitions for groups of formatting objects </xsl:comment><xsl:text>
  53. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  54. </xsl:text>
  55. <xsl:apply-templates select="./xs:simpleType"/>
  56. <xsl:text>
  57. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  58. </xsl:text><xsl:comment> Attribute Groups </xsl:comment><xsl:text>
  59. </xsl:text><xsl:comment> *************************************************************** </xsl:comment>
  60. <xsl:apply-templates select="./xs:attributeGroup"/>
  61. <xsl:text>
  62. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  63. </xsl:text><xsl:comment> Element Groups </xsl:comment><xsl:text>
  64. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  65. </xsl:text>
  66. <xsl:apply-templates select="./xs:group"/>
  67. <xsl:text>
  68. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  69. </xsl:text><xsl:comment> Elements </xsl:comment><xsl:text>
  70. </xsl:text><xsl:comment> *************************************************************** </xsl:comment><xsl:text>
  71. </xsl:text>
  72. <xsl:apply-templates select="./xs:element"/>
  73. </xsl:template>
  74. <xsl:template match="xs:group">
  75. <xsl:text disable-output-escaping="yes">
  76. &lt;!ENTITY % </xsl:text><xsl:value-of select="./@name"/><xsl:text> "</xsl:text>
  77. <xsl:for-each select="./xs:choice/xs:element">
  78. <xsl:text>
  79. </xsl:text>
  80. <xsl:value-of select="./@ref"/>
  81. <xsl:if test="position() != last()">
  82. <xsl:text> |</xsl:text>
  83. </xsl:if>
  84. </xsl:for-each>
  85. <xsl:if test="./xs:choice/xs:group">
  86. <xsl:variable name="ref1">
  87. <xsl:call-template name="strip_fo">
  88. <xsl:with-param name="ref" select="./xs:choice/xs:group[1]/@ref"/>
  89. </xsl:call-template>
  90. </xsl:variable>
  91. <xsl:variable name="ref2">
  92. <xsl:call-template name="strip_fo">
  93. <xsl:with-param name="ref" select="./xs:choice/xs:group[2]/@ref"/>
  94. </xsl:call-template>
  95. </xsl:variable>
  96. <xsl:text>
  97. %</xsl:text>
  98. <xsl:value-of select="$ref1"/>
  99. <xsl:text>;</xsl:text>
  100. <xsl:if test="(/xs:schema/xs:group[@name = $ref1]/xs:choice/xs:element) and (/xs:schema/xs:group[@name = $ref2]/xs:choice/xs:element)">
  101. <xsl:text>| </xsl:text>
  102. </xsl:if>
  103. <xsl:text>
  104. %</xsl:text>
  105. <xsl:value-of select="$ref2"/><xsl:text>;</xsl:text>
  106. </xsl:if>
  107. <xsl:text disable-output-escaping="yes">
  108. "&gt;</xsl:text>
  109. </xsl:template>
  110. <xsl:template match="xs:attributeGroup">
  111. <xsl:text disable-output-escaping="yes">
  112. &lt;!ENTITY % </xsl:text><xsl:value-of select="./@name"/><xsl:text> "</xsl:text>
  113. <xsl:for-each select="./xs:attribute">
  114. <xsl:variable name="name">
  115. <xsl:call-template name="strip_fo">
  116. <xsl:with-param name="ref" select="./@name"/>
  117. </xsl:call-template>
  118. </xsl:variable>
  119. <xsl:variable name="type">
  120. <xsl:call-template name="strip_fo">
  121. <xsl:with-param name="ref" select="./@type"/>
  122. </xsl:call-template>
  123. </xsl:variable>
  124. <xsl:text>
  125. </xsl:text>
  126. <xsl:value-of select="$name"/>
  127. <xsl:choose>
  128. <xsl:when test="$type = 'xs:string'">
  129. <xsl:text> CDATA</xsl:text>
  130. </xsl:when>
  131. <xsl:when test="/xs:schema/xs:simpleType[@name = $type]/xs:restriction/xs:enumeration">
  132. <!--This item is a directly enumerated type-->
  133. <xsl:text> (%</xsl:text>
  134. <xsl:value-of select="$type"/>
  135. <xsl:text>;)</xsl:text>
  136. </xsl:when>
  137. <xsl:otherwise>
  138. <xsl:text> CDATA</xsl:text>
  139. </xsl:otherwise>
  140. </xsl:choose>
  141. <xsl:text> #IMPLIED</xsl:text>
  142. </xsl:for-each>
  143. <xsl:for-each select="./xs:attributeGroup">
  144. <xsl:variable name="ref">
  145. <xsl:call-template name="strip_fo">
  146. <xsl:with-param name="ref" select="./@ref"/>
  147. </xsl:call-template>
  148. </xsl:variable>
  149. <xsl:text>
  150. %</xsl:text><xsl:value-of select="$ref"/><xsl:text>;</xsl:text>
  151. </xsl:for-each>
  152. <xsl:text disable-output-escaping="yes">
  153. "&gt;</xsl:text>
  154. </xsl:template>
  155. <xsl:template match="xs:simpleType">
  156. <xsl:if test="./xs:restriction/xs:enumeration">
  157. <xsl:text disable-output-escaping="yes">
  158. &lt;!ENTITY % </xsl:text><xsl:value-of select="./@name"/><xsl:text> "</xsl:text>
  159. <xsl:for-each select="./xs:restriction/xs:enumeration">
  160. <xsl:value-of select="./@value"/>
  161. <xsl:if test="position() != last()">
  162. <xsl:text>|</xsl:text>
  163. </xsl:if>
  164. </xsl:for-each>
  165. <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
  166. </xsl:if>
  167. </xsl:template>
  168. <xsl:template match="xs:element">
  169. <xsl:text disable-output-escaping="yes">&lt;!ELEMENT fo:</xsl:text>
  170. <xsl:value-of select="./@name"/>
  171. <xsl:choose>
  172. <xsl:when test="( not(./xs:complexType/xs:sequence) and not(./xs:complexType/xs:choice) )">
  173. <xsl:text> EMPTY</xsl:text>
  174. </xsl:when>
  175. <xsl:otherwise>
  176. <xsl:text> (</xsl:text>
  177. <xsl:if test="./xs:complexType/@mixed = 'true'">
  178. <xsl:text>#PCDATA|</xsl:text>
  179. </xsl:if>
  180. <xsl:for-each select="./xs:complexType/xs:sequence">
  181. <xsl:for-each select="./xs:element">
  182. <xsl:value-of select="./@ref"/>
  183. <xsl:call-template name="addPlus"/>
  184. <xsl:if test="position() != last()">
  185. <xsl:text>,</xsl:text>
  186. </xsl:if>
  187. </xsl:for-each>
  188. <xsl:for-each select="./xs:group">
  189. <xsl:text>%</xsl:text>
  190. <xsl:variable name="ref">
  191. <xsl:call-template name="strip_fo">
  192. <xsl:with-param name="ref" select="./@ref"/>
  193. </xsl:call-template>
  194. </xsl:variable>
  195. <xsl:value-of select="$ref"/>
  196. <xsl:text>;</xsl:text>
  197. <xsl:call-template name="addPlus"/>
  198. <xsl:if test="position() != last()">
  199. <xsl:text>,</xsl:text>
  200. </xsl:if>
  201. </xsl:for-each>
  202. </xsl:for-each>
  203. <xsl:for-each select="./xs:complexType/xs:choice">
  204. <xsl:for-each select="./xs:element">
  205. <xsl:value-of select="./@ref"/>
  206. <xsl:call-template name="addPlus"/>
  207. <xsl:if test="position() != last()">
  208. <xsl:text>|</xsl:text>
  209. </xsl:if>
  210. </xsl:for-each>
  211. <xsl:for-each select="./xs:group">
  212. <xsl:text>%</xsl:text>
  213. <xsl:variable name="ref">
  214. <xsl:call-template name="strip_fo">
  215. <xsl:with-param name="ref" select="./@ref"/>
  216. </xsl:call-template>
  217. </xsl:variable>
  218. <xsl:value-of select="$ref"/>
  219. <xsl:text>;</xsl:text>
  220. <xsl:call-template name="addPlus"/>
  221. <xsl:if test="position() != last()">
  222. <xsl:text>|</xsl:text>
  223. </xsl:if>
  224. </xsl:for-each>
  225. </xsl:for-each>
  226. <xsl:text>)</xsl:text>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. <xsl:for-each select="./xs:complexType/xs:sequence">
  230. <xsl:call-template name="addPlus"/>
  231. </xsl:for-each>
  232. <xsl:for-each select="./xs:complexType/xs:choice">
  233. <xsl:call-template name="addPlus"/>
  234. </xsl:for-each>
  235. <xsl:text disable-output-escaping="yes">&gt;
  236. &lt;!ATTLIST fo:</xsl:text>
  237. <xsl:value-of select="./@name"/>
  238. <xsl:for-each select="./xs:complexType/xs:attribute">
  239. <xsl:variable name="name">
  240. <xsl:call-template name="strip_fo">
  241. <xsl:with-param name="ref" select="./@name"/>
  242. </xsl:call-template>
  243. </xsl:variable>
  244. <xsl:variable name="type">
  245. <xsl:call-template name="strip_fo">
  246. <xsl:with-param name="ref" select="./@type"/>
  247. </xsl:call-template>
  248. </xsl:variable>
  249. <xsl:text>
  250. </xsl:text>
  251. <xsl:value-of select="$name"/>
  252. <xsl:choose>
  253. <xsl:when test="$type = 'xs:string'">
  254. <xsl:text> CDATA</xsl:text>
  255. </xsl:when>
  256. <xsl:when test="/xs:schema/xs:simpleType[@name = $type]/xs:restriction/xs:enumeration">
  257. <!--This item is a directly enumerated type-->
  258. <xsl:text> (%</xsl:text>
  259. <xsl:value-of select="$type"/>
  260. <xsl:text>;)</xsl:text>
  261. </xsl:when>
  262. <xsl:otherwise>
  263. <xsl:text> CDATA</xsl:text>
  264. </xsl:otherwise>
  265. </xsl:choose>
  266. <xsl:choose>
  267. <xsl:when test="@use = 'required'">
  268. <xsl:text> #REQUIRED</xsl:text>
  269. </xsl:when>
  270. <xsl:otherwise>
  271. <xsl:text> #IMPLIED</xsl:text>
  272. </xsl:otherwise>
  273. </xsl:choose>
  274. </xsl:for-each>
  275. <xsl:for-each select="./xs:complexType/xs:attributeGroup">
  276. <xsl:variable name="ref">
  277. <xsl:call-template name="strip_fo">
  278. <xsl:with-param name="ref" select="./@ref"/>
  279. </xsl:call-template>
  280. </xsl:variable>
  281. <xsl:text>
  282. %</xsl:text>
  283. <xsl:value-of select="$ref"/>
  284. <xsl:text>;</xsl:text>
  285. </xsl:for-each>
  286. <xsl:text disable-output-escaping="yes">
  287. &gt;
  288. </xsl:text>
  289. </xsl:template>
  290. <xsl:template name="addPlus">
  291. <xsl:choose>
  292. <xsl:when test="(@minOccurs = 0) and (@maxOccurs = 'unbounded')">
  293. <xsl:text>*</xsl:text>
  294. </xsl:when>
  295. <xsl:when test="(@minOccurs = 0) and ((@maxOccurs = 1) or not(@maxOccurs))">
  296. <xsl:text>?</xsl:text>
  297. </xsl:when>
  298. <xsl:when test="((@minOccurs = 1) or not(@minOccurs)) and (@maxOccurs = 'unbounded')">
  299. <xsl:text>+</xsl:text>
  300. </xsl:when>
  301. <xsl:when test="not(@minOccurs) and not(@maxOccurs)">
  302. </xsl:when>
  303. <xsl:otherwise>
  304. <xsl:text>!error!</xsl:text>
  305. </xsl:otherwise>
  306. </xsl:choose>
  307. </xsl:template>
  308. <xsl:template name="strip_fo">
  309. <xsl:param name="ref"/>
  310. <xsl:choose>
  311. <xsl:when test="substring($ref,1,3) = 'fo:'">
  312. <xsl:value-of select="substring($ref,4)"/>
  313. </xsl:when>
  314. <xsl:otherwise>
  315. <xsl:value-of select="$ref"/>
  316. </xsl:otherwise>
  317. </xsl:choose>
  318. </xsl:template>
  319. </xsl:stylesheet>