Is it possible to use an attributes value as part of a pattern match?
eg xsd:
<xs:element name="MyElement">
<xs:complexType>
<xs:sequence>
<xs:element ref="SomeElement" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="MyTestElement">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(Attribute name value) some other regex matching"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
so basically the pattern match in MyTestElement should include the value of the outer elements name attribute, is this possible?
You can't use XPath in a
xs:pattern
. The content ofxs:pattern
should be a pattern (regular expression) as it is said in the specs.However you can use XPath in
xs:assert
and others if you are using XSD 1.1, and some XPath subset insidexs:key
,xs:keyRef
andxs:unique
if you are using XSD 1.0.For example if you were using XSD 1.1 you could use an assertion like this to check that every
<MyTestElement>
matches a pattern or has the same value than the name attribute.