Reputation: 3278
I have several xsd's that I do not own, that need to be converted to an in-house xml standard to work within our application.
There is an xslt script that does this for us through an ant task, but now we've come to a roadblock:
when the xsd contains an xs:import
statement, the xslt will not be able to find the fields defined in the referenced xsd.
example xsd's:
main.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema>
<xs:import namespace="urn:company:ns.common" schemaLocation="common.xsd"/>
<xs:complexType name="User">
<xs:element ref="common:Address">
</xs:complexType>
</xs:schema>
common.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="urn:company:ns.common">
<xs:complexType name="Address">
<xs:sequence>
<xs:element name="Street" type="xs:string"/>
<xs:element name="HouseNumber" type="xs:number"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
while I can't show the current xslt since it would be akin to divulging some company information, the expected output should be something like this:
<User>
<Address>
<Street></Street>
<HouseNumber></HouseNumber>
</Address>
</User>
at this time, the xslt ignores what it can't find when it is inside the imported xsd.
wrong result:
<User></User>
Upvotes: 0
Views: 164
Reputation: 111581
Without making one or more simplifying assumptions, you have a complex subproject on your hands, not a SO Q/A. I'll suggest a key simplifying assumption:
If you can make this simplifying assumption, then consider adjusting the xsd:imports
basically to be xsd:includes
and then using XSD flattening via
the tool available in many commercial XML/XSD editors, or
W. Paul Kiel's XML SchemaLightener, which has a flatten function, as a tool or as a starting point as it's written in XSLT
Your XSLT could then take the single, flattened XSD as input rather than the collection of separate XSDs.
Upvotes: 1