I am trying to build an XSD which constrains a particular node to be an “inline” stylesheet.
It would probably look something like this:
<complexType name="InlineXslt">
<sequence>
<any minOccurs="1" maxOccurs="1" FORCE_NAMESPACE="http://www.w3.org/1999/XSL/Transform" />
</sequence>
</complexType>
or perhaps…
<complexType name="InlineXslt">
<sequence>
<element name="stylesheet" minOccurs="1" maxOccurs="1" FORCE_NAMESPACE="http://www.w3.org/1999/XSL/Transform" />
</sequence>
</complexType>
Of course there is no FORCE_NAMESPACE attribute, but the idea is to force the node to use the XSL namespace. Is there an equivelant syntax that would allow me to specify this restriction? The conforming XML would look like this:
<InlineXslt>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<... etc ...>
</stylesheet>
</InlineXslt>
If I omit the (non-existent) “FORCE_NAMESPACE” attribute on the first XSD example, it does work, but it is not enforced. Due to the use of the “any” element, the user could put anything they want in there, including a node which isn’t named “stylesheet” and using any namespace they choose.
Short answer:
The
FORCE_NAMESPACEattribute you would like forxs:anyexists; it’s callednamespace. (It may differ from your FORCE_NAMESPACE in allowing more than one namespace name.) TheFORCE_NAMESPACEattribute you would like forxs:elementdoes not exist, because it’s not needed; the functionality you are looking for is achieved using therefattribute and a qualified name.Longer answer:
If you want elements whose type is InlineXslt to contain an xslt:stylesheet element, the simplest way to achieve it is to say so:
This will require that your schema document import the XSLT namespace, so at the top of the schema document you’ll have something like:
If you want to allow the top-level element to be either
stylesheetortransform, write a choice:If you want to allow arbitrary XSLT elements (sounds like a semantic nightmare in your particular case, but as an example), use a wildcard that specifies that any element from the XSLT namespace is accepted: