xsdtest.xsl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:strip-space elements="xsdtest datatype equiv class"/>
  4. <xsl:output indent="yes" encoding="utf-8"/>
  5. <xsl:template match="xsdtest">
  6. <testSuite>
  7. <xsl:apply-templates/>
  8. </testSuite>
  9. </xsl:template>
  10. <xsl:template match="datatype">
  11. <testSuite>
  12. <documentation>Datatype <xsl:value-of select="@name"/></documentation>
  13. <testCase>
  14. <requires datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"/>
  15. <correct>
  16. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  17. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  18. <data type="{@name}">
  19. <xsl:for-each select="param">
  20. <param name="{@name}"><xsl:value-of select="."/></param>
  21. </xsl:for-each>
  22. </data>
  23. </element>
  24. </correct>
  25. <xsl:apply-templates select="valid|invalid"/>
  26. </testCase>
  27. <xsl:apply-templates select="equiv/class|length|lessThan|incomparable"/>
  28. </testSuite>
  29. </xsl:template>
  30. <xsl:template match="valid">
  31. <xsl:call-template name="valid"/>
  32. </xsl:template>
  33. <xsl:template match="invalid">
  34. <xsl:call-template name="invalid"/>
  35. </xsl:template>
  36. <xsl:template name="valid">
  37. <valid>
  38. <xsl:apply-templates select="@internalSubset"/>
  39. <doc>
  40. <xsl:copy-of select="namespace::*"/>
  41. <xsl:value-of select="."/>
  42. </doc>
  43. </valid>
  44. </xsl:template>
  45. <xsl:template name="invalid">
  46. <invalid>
  47. <xsl:apply-templates select="@internalSubset"/>
  48. <doc>
  49. <xsl:copy-of select="namespace::*"/>
  50. <xsl:value-of select="."/>
  51. </doc>
  52. </invalid>
  53. </xsl:template>
  54. <xsl:template match="@internalSubset">
  55. <xsl:param name="doc" select="'doc'"/>
  56. <xsl:attribute name="dtd">
  57. <xsl:text>
  58. &lt;!DOCTYPE </xsl:text>
  59. <xsl:value-of select="$doc"/>
  60. <xsl:text> [
  61. </xsl:text>
  62. <xsl:value-of select="."/>
  63. <xsl:text>
  64. ]></xsl:text>
  65. </xsl:attribute>
  66. </xsl:template>
  67. <xsl:template match="class">
  68. <testCase>
  69. <correct>
  70. <xsl:for-each select="value[1]">
  71. <xsl:apply-templates select="@internalSubset">
  72. <xsl:with-param name="doc">element</xsl:with-param>
  73. </xsl:apply-templates>
  74. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  75. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  76. <value>
  77. <xsl:copy-of select="namespace::*"/>
  78. <xsl:attribute name="type"><xsl:value-of select="../../../@name"/></xsl:attribute>
  79. <xsl:value-of select="."/>
  80. </value>
  81. </element>
  82. </xsl:for-each>
  83. </correct>
  84. <xsl:for-each select="value[position() != 1]">
  85. <xsl:call-template name="valid"/>
  86. </xsl:for-each>
  87. <xsl:for-each select="preceding-sibling::class/value|following-sibling::class/value">
  88. <xsl:call-template name="invalid"/>
  89. </xsl:for-each>
  90. </testCase>
  91. </xsl:template>
  92. <xsl:template match="length">
  93. <testCase>
  94. <correct>
  95. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  96. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  97. <data type="{../@name}">
  98. <param name="length"><xsl:value-of select="@value"/></param>
  99. </data>
  100. </element>
  101. </correct>
  102. <xsl:call-template name="valid"/>
  103. </testCase>
  104. <testCase>
  105. <correct>
  106. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  107. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  108. <data type="{../@name}">
  109. <param name="length"><xsl:value-of select="@value + 1"/></param>
  110. </data>
  111. </element>
  112. </correct>
  113. <xsl:call-template name="invalid"/>
  114. </testCase>
  115. <xsl:if test="@value != 0">
  116. <testCase>
  117. <correct>
  118. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  119. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  120. <data type="{../@name}">
  121. <param name="length"><xsl:value-of select="@value - 1"/></param>
  122. </data>
  123. </element>
  124. </correct>
  125. <xsl:call-template name="invalid"/>
  126. </testCase>
  127. </xsl:if>
  128. </xsl:template>
  129. <xsl:template match="lessThan">
  130. <testCase>
  131. <correct>
  132. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  133. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  134. <data type="{../@name}">
  135. <param name="minExclusive">
  136. <xsl:value-of select="value[1]"/>
  137. </param>
  138. </data>
  139. </element>
  140. </correct>
  141. <valid>
  142. <doc>
  143. <xsl:value-of select="value[2]"/>
  144. </doc>
  145. </valid>
  146. <invalid>
  147. <doc>
  148. <xsl:value-of select="value[1]"/>
  149. </doc>
  150. </invalid>
  151. </testCase>
  152. <testCase>
  153. <correct>
  154. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  155. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  156. <data type="{../@name}">
  157. <param name="minExclusive">
  158. <xsl:value-of select="value[2]"/>
  159. </param>
  160. </data>
  161. </element>
  162. </correct>
  163. <invalid>
  164. <doc>
  165. <xsl:value-of select="value[1]"/>
  166. </doc>
  167. </invalid>
  168. <invalid>
  169. <doc>
  170. <xsl:value-of select="value[2]"/>
  171. </doc>
  172. </invalid>
  173. </testCase>
  174. </xsl:template>
  175. <xsl:template match="incomparable">
  176. <testCase>
  177. <correct>
  178. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  179. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  180. <data type="{../@name}">
  181. <param name="minExclusive">
  182. <xsl:value-of select="value[1]"/>
  183. </param>
  184. </data>
  185. </element>
  186. </correct>
  187. <invalid>
  188. <doc>
  189. <xsl:value-of select="value[2]"/>
  190. </doc>
  191. </invalid>
  192. <invalid>
  193. <doc>
  194. <xsl:value-of select="value[1]"/>
  195. </doc>
  196. </invalid>
  197. </testCase>
  198. <testCase>
  199. <correct>
  200. <element xmlns="http://relaxng.org/ns/structure/1.0" name="doc"
  201. datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  202. <data type="{../@name}">
  203. <param name="minExclusive">
  204. <xsl:value-of select="value[2]"/>
  205. </param>
  206. </data>
  207. </element>
  208. </correct>
  209. <invalid>
  210. <doc>
  211. <xsl:value-of select="value[1]"/>
  212. </doc>
  213. </invalid>
  214. <invalid>
  215. <doc>
  216. <xsl:value-of select="value[2]"/>
  217. </doc>
  218. </invalid>
  219. </testCase>
  220. </xsl:template>
  221. </xsl:stylesheet>