-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXSD2SCH.xml
226 lines (205 loc) · 10.5 KB
/
XSD2SCH.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<project
name="ant-hology.taskdefs.XSD2SCH"
basedir="."
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<dirname property="ant-hology.taskdefs.XSD2SCH.dir" file="${ant.file.ant-hology.taskdefs.XSD2SCH}"/>
<import file="${ant-hology.dir}/commonProperties.xml" unless:set="ant-hology.commonProperties.loaded"/>
<import file="${ant-hology.taskdefs.dir}/test.areAllAvailable.xml" unless:set="ant-hology.taskdefs.test.areAllAvailable.loaded"/>
<import file="${ant-hology.taskdefs.dir}/property.set.fileName.xml" unless:set="ant-hology.taskdefs.property.set.fileName.loaded"/>
<import file="${ant-hology.taskdefs.dir}/xmlvalidate-xmlcatalog.xml" unless:set="ant-hology.taskdefs.xmlvalidate-xmlcatalog.loaded"/>
<import file="${ant-hology.taskdefs.dir}/schemavalidate-xmlcatalog.xml" unless:set="ant-hology.taskdefs.schemavalidate-xmlcatalog.loaded"/>
<import file="${ant-hology.taskdefs.dir}/task-jing.xml" unless:set="ant-hology.taskdefs.task-jing.loaded"/>
<import file="${ant-hology.taskdefs.dir}/task-saxonb.xml" unless:set="ant-hology.taskdefs.task-saxonb.loaded"/>
<import file="${ant-hology.pathdefs.dir}/saxonHE.xml" unless:set="ant-hology.pathdefs.saxonHE.loaded"/>
<import file="${ant-hology.pathdefs.dir}/apache-xerces.xml" unless:set="ant-hology.pathdefs.apache-xerces.loaded"/>
<import file="${ant-hology.pathdefs.dir}/apache-commons-xmlresolver.xml" unless:set="ant-hology.pathdefs.apache-commons-xmlresolver.loaded"/>
<import file="${ant-hology.pathdefs.dir}/xmlcatalog.xml" unless:set="ant-hology.pathdefs.xmlcatalog.loaded"/>
<import file="${ant-hology.pathdefs.dir}/ant-schematron.xml" unless:set="ant-hology.pathdefs.ant-schematron.loaded"/>
<import file="${ant-hology.pathdefs.dir}/iso-schematron-xslt1.xml" unless:set="ant-hology.pathdefs.iso-schematron-xslt1.loaded"/>
<import file="${ant-hology.pathdefs.dir}/iso-schematron-xslt2.xml" unless:set="ant-hology.pathdefs.iso-schematron-xslt2.loaded"/>
<import file="${ant-hology.pathdefs.dir}/XSD2SCH.xml" unless:set="ant-hology.pathdefs.XSD2SCH.loaded"/>
<areAllAvailable
property="ant-hology.availableLibraries.saxonHE"
pathRefId="saxonHE.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.apache-xerces"
pathRefId="apache-xerces.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.apache-commons-xmlresolver"
pathRefId="apache-commons-xmlresolver.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.xmlcatalog"
pathRefId="xmlcatalog.required"
/>
<areAllAvailable
property="ant-hology.availableLibraries.ant-schematron"
pathRefId="ant-schematron.classpath"
/>
<areAllAvailable
property="ant-hology.availableLibraries.iso-schematron-xslt1"
pathRefId="iso-schematron-xslt1.required"/>
<areAllAvailable
property="ant-hology.availableLibraries.iso-schematron-xslt2"
pathRefId="iso-schematron-xslt2.required"/>
<areAllAvailable
property="ant-hology.availableLibraries.XSD2SCH"
pathRefId="XSD2SCH.required"/>
<local name="_requiredAvailable"/>
<condition property="_requiredAvailable">
<and>
<isset property="ant-hology.availableLibraries.saxonHE"/>
<isset property="ant-hology.availableLibraries.apache-xerces"/>
<isset property="ant-hology.availableLibraries.apache-commons-xmlresolver"/>
<isset property="ant-hology.availableLibraries.xmlcatalog"/>
<isset property="ant-hology.availableLibraries.ant-schematron"/>
<isset property="ant-hology.availableLibraries.iso-schematron-xslt1"/>
<isset property="ant-hology.availableLibraries.iso-schematron-xslt2"/>
<isset property="ant-hology.availableLibraries.XSD2SCH"/>
</and>
</condition>
<!-- See https://code.google.com/p/schematron/#XSD_to_Schematron_Converter -->
<!-- This is similar to the target build-small.xml that comes with -->
<!-- https://schematron.googlecode.com/files/XSD2SCH-2010-03-11.zip -->
<!-- However in this case, it is a macrodef task. -->
<macrodef
name="XSD2SCH"
description="Transform a single XSD to schematron SCH."
if:set="_requiredAvailable"
>
<attribute
name="srcfile"
description="The source XSD schema input."
/>
<attribute
name="destfile"
description="The SCH schema output."
/>
<attribute
name="schematron.rnc"
default="${xmlcatalog.dir}/schematron/iso/iso-schematron.rnc"
description="Full path to the iso-schematron.rnc which is used for validating SCH generated by this macrodef."
/>
<attribute
name="xmlschema.xsd"
default="${xmlcatalog.dir}/www.w3.org/xmlschema/XMLSchema.xsd"
description="Full path to the XMLSchema.xsd which is used for validating @{srcfile} before attempting conversion to SCH."
/>
<attribute
name="deleteTempFiles"
default="true"
description="If true, then temporary files created by XSD2SCH task will be deleted when completed successfully."
/>
<attribute
name="validateXSDInput"
default="true"
description="If true, then the XSD input file will be validated against @{xmlschema.xsd}. Any other value is considered false."
/>
<attribute
name="validateSCHOutput"
default="false"
description="If true, then the SCH file created will be validated against @{schematron.rnc}. Any other value is considered false."
/>
<sequential>
<local name="_xsdPath"/>
<property name="_xsdPath" location="@{srcfile}"/>
<local name="_xsdFileName"/>
<property.set.fileName property="_xsdFileName" filepath="${_xsdPath}"/>
<local name="_schPath"/>
<property name="_schPath" location="@{destfile}"/>
<local name="_schFileName"/>
<property.set.fileName property="_schFileName" filepath="${_schPath}"/>
<local name="_schDirPath"/>
<property name="_schDirPath" location="${_schPath}/.."/>
<!--Transforms input @{schematron.rnc} to property appropriate for OS type-->
<local name="_schematron.rnc"/>
<property name="_schematron.rnc" location="@{schematron.rnc}"/>
<!--<echo>_schematron.rnc=${_schematron.rnc}</echo>-->
<!--Transforms input @{xmlschema.xsd} to property appropriate for OS type-->
<local name="_xmlschema.xsd"/>
<property name="_xmlschema.xsd" location="@{xmlschema.xsd}"/>
<!--<echo>_xmlschema.xsd=${_xmlschema.xsd}</echo>-->
<echo>Converting XSD to SCH: "@{srcfile}" to "@{destfile}"</echo>
<echo>Converting XSD to SCH: First validating XSD input</echo>
<local name="_validateXSDInput"/>
<condition property="_validateXSDInput" value="true">
<equals arg1="@{validateXSDInput}" arg2="true"/>
</condition>
<schemavalidate-xmlcatalog
file="${_xsdPath}"
failonerror="true"
lenient="no"
warn="yes"
if:set="_validateXSDInput"
>
<schema
namespace="http://www.w3.org/2001/XMLSchema"
file="${_xmlschema.xsd}"
/>
</schemavalidate-xmlcatalog>
<!--Note: saxonHE sometimes fails with include.xsl on certain xsd inputs, so using saxonb-->
<!-- See http://www.oreillynet.com/xml/blog/2007/10/converting_xml_schemas_to_sche_1.html -->
<!-- include, flatten and expand steps of pipeline -->
<echo>Converting XSD to SCH: Normalizing XSD step 1 (include)</echo>
<mkdir dir="${ant-hology.temp.dir}"/>
<saxonb
srcfile="${_xsdPath}"
destfile="${ant-hology.temp.dir}/${_xsdFileName}.xsd-incl"
xsl="${ant-hology.lib.dir}/XSD2SCH-2010-03-11/xslt/include.xsl"
/>
<echo>Converting XSD to SCH: Normalizing XSD step 2 (flatten)</echo>
<saxonb
srcfile="${ant-hology.temp.dir}/${_xsdFileName}.xsd-incl"
destfile="${ant-hology.temp.dir}/${_xsdFileName}.xsd-flat"
xsl="${ant-hology.lib.dir}/XSD2SCH-2010-03-11/xslt/flatten.xsl"
/>
<echo>Converting XSD to SCH: Normalizing XSD step 3 (expand)</echo>
<saxonb
srcfile="${ant-hology.temp.dir}/${_xsdFileName}.xsd-flat"
destfile="${ant-hology.temp.dir}/${_xsdFileName}.xsd-expand"
xsl="${ant-hology.lib.dir}/XSD2SCH-2010-03-11/xslt/expand.xsl"
/>
<echo>Converting XSD to SCH: Transforming XSD to SCH (uncompressed)</echo>
<saxonb
srcfile="${ant-hology.temp.dir}/${_xsdFileName}.xsd-expand"
destfile="${ant-hology.temp.dir}/${_schFileName}.uncompressed.sch"
xsl="${ant-hology.lib.dir}/XSD2SCH-2010-03-11/xslt/xsd2sch.xsl"
/>
<!-- See http://www.oreillynet.com/xml/blog/2007/10/converting_xml_schemas_to_sche_2.html -->
<echo>Converting XSD to SCH: Compressing SCH</echo>
<saxonb
srcfile="${ant-hology.temp.dir}/${_schFileName}.uncompressed.sch"
destfile="${_schPath}"
xsl="${ant-hology.lib.dir}/XSD2SCH-2010-03-11/xslt/compress.xsl"
/>
<echo>Converting XSD to SCH: Finally validate SCH created against the iso-schematron.rnc grammar</echo>
<!--Note: The SCH often has empty rules that are benign but the iso-schematron.rnc complains about them.-->
<!-- As well, the SCH has some tags that are not defined iso-schematron.rnc-->
<!-- These validation issues are usually benign but should be reviewed.-->
<!-- Because they are usually benign, there is an option @{validateSCHOutput} that defaults to false-->
<local name="_validateSCHOutput"/>
<condition property="_validateSCHOutput" value="true">
<equals arg1="@{validateSCHOutput}" arg2="true"/>
</condition>
<jing rngfile="${_schematron.rnc}" compactsyntax="true" if:set="_validateSCHOutput">
<fileset file="${_schPath}"/>
</jing>
<!--Delete temporary files if @{deleteTempFiles} is true-->
<local name="_deleteTempFiles"/>
<condition property="_deleteTempFiles" value="true">
<equals arg1="@{deleteTempFiles}" arg2="true"/>
</condition>
<echo if:set="_deleteTempFiles">Converting XSD to SCH: Deleting temporary files</echo>
<delete file="${ant-hology.temp.dir}/${_xsdFileName}.xsd-incl" if:set="_deleteTempFiles"/>
<delete file="${ant-hology.temp.dir}/${_xsdFileName}.xsd-flat" if:set="_deleteTempFiles"/>
<delete file="${ant-hology.temp.dir}/${_xsdFileName}.xsd-expand" if:set="_deleteTempFiles"/>
<delete file="${ant-hology.temp.dir}/${_schFileName}.uncompressed.sch" if:set="_deleteTempFiles"/>
</sequential>
</macrodef>
<property name="ant-hology.taskdefs.XSD2SCH.loaded" value="true"/>
</project>