XMLSchema pattern based on attribute

P

patrik.nyman

I'm wondering if this can be done within an XMLSchema:

I want to define an element <identifier> as having an attribute "type"
with one of a given list of values.
Based on what value is chosen, I want the *content* of the element to
be restricted to
following a certain pattern or being of a certain type.

For example, <identifier type="uri"> must contain something on the
pattern
"[a-z:]+[\d-]", while the content of <foo type="isbn"> must follow the
pattern "[\d-]+".

The code I have is

<xs:element name="identifier">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="kb:att.identifier.type"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

<xs:attributeGroup name="att.identifier.type">
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="issn"/>
<xs:enumeration value="isbn"/>
<xs:enumeration value="uri"/>
<xs:enumeration value="internal"/>
<xs:enumeration value="iso639-1"/>
<xs:enumeration value="iso639-2"/>
<xs:enumeration value="iso3166-1"/>
<xs:enumeration value="pmid"/>
<xs:enumeration value="keyTitle"/>
<xs:enumeration value="patentNumber"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
 
P

Pavel Lepin

(e-mail address removed) < (e-mail address removed)>
wrote in
I'm wondering if this can be done within an XMLSchema:

This is funny. I know very little of XML Schemata, because I
normally don't use those in my work, but I have a strong
feeling that the answer is 'no', because...
I want to define an element <identifier> as having an
attribute "type" with one of a given list of values.
Based on what value is chosen, I want the *content* of the
element to be restricted to
following a certain pattern or being of a certain type.

For example, <identifier type="uri"> must contain
something on the pattern
"[a-z:]+[\d-]", while the content of <foo type="isbn">
must follow the pattern "[\d-]+".

....this question has been answered on this group no less
than *twice* in the last ten days:

<http://groups.google.com/group/comp.text.xml/msg/f230e4846613e07f>
<http://groups.google.com/group/comp.text.xml/msg/c1d229fef79a927b>

Google is your friend.
 
J

Joseph Kesselman

I want to define an element <identifier> as having an attribute "type"
with one of a given list of values.
Based on what value is chosen, I want the *content* of the element to
be restricted to
following a certain pattern or being of a certain type.

The closest you can come to that in XML Schema is to use xsl:type to
explicitly select among several types derived from a common type. Schema
won't let you make that decision implicitly based on other document content.
 
P

patrik.nyman

The closest you can come to that in XML Schema is to use xsl:type to
explicitly select among several types derived from a common type. Schema
won't let you make that decision implicitly based on other document content.

Thanks for that clarification. I actually read your post from a few
days ago
when you explained this, but then I forgot about it until reminded by
Pavel. I wish memory too was my friend. :)

Patrik Nyman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top