Hi,
I want to embed a Schematron validation (which allows Xpath) in XSD.
Example below is to validate "subjectLevel" element. First subjectLevel"
element should have the value "Yes" and "subjectLevel" element other than
the first position should have value "No". I tried using "xs:annotation" to
embed Schmatron rules in XSD but while validating the xml against that XSD,
I am not getting Schematron validation error.
Please let me know if there is any other approach of doing this kind of
Schematron validation inside XSD.
--------------------------------------------------------------------------------
> ***XML to validate:***
--------------------------------------------------------------------------------
<correlationResponse>
<correlationElement>
<subjectLevel>No</subjectLevel>
</correlationElement>
<correlationElement>
<subjectLevel>Yes</subjectLevel>
</correlationElement>
</correlationResponse>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> ***Schematron:***
--------------------------------------------------------------------------------
<schema
schemaVersion = "3.3.1"
xmlns = "http://purl.oclc.org/dsdl/schematron"
xmlns:s = "http://purl.oclc.org/dsdl/schematron"
xmlns:dp = "http://www.dpawson.co.uk/ns#">
<pattern>
<title>subjectLevel value based on correlationElement order</title>
<rule context = "/correlationResponse/correlationElement[position()
= 1]">
<assert test = "subjectLevel = 'Yes'">subjectLevel value of
first correlationElement must be "Yes"</assert>
</rule>
<rule context = "/correlationResponse/correlationElement[position()
!= 1]">
<assert test = "subjectLevel = 'No'">subjectLevel value other
than first correlationElement must be "No"</assert>
</rule>
</pattern>
</schema>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> ***Schema:***
--------------------------------------------------------------------------------
<xs:schema
xmlns:xs = "http://www.w3.org/2001/XMLSchema"
elementFormDefault = "qualified"
attributeFormDefault = "unqualified">
<!--XML Schema Generated from XML Document on Fri May 29 2015 17:23:05
GMT+0530 (India Standard Time) -->
<!--with XmlGrid.net Free Online Service http://xmlgrid.net -->
<xs:element name = "correlationResponse">
<xs:complexType>
<xs:sequence>
<xs:element name = "correlationElement" maxOccurs =
"unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name = "subjectLevel" type =
"xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
> ***Solution tried***
--------------------------------------------------------------------------------
<xs:annotation>
<xs:appinfo>
<sch:pattern>
<sch:title>subjectLevel value based on correlationElement
order</sch:title>
<sch:rule abstract = "false" context =
"/correlationResponse/correlationElement[position() = 1]">
<sch:assert test = "subjectLevel = 'Yes'">subjectLevel
value of first correlationElement must be "Yes"
.</sch:assert>
</sch:rule>
<sch:rule abstract = "false" context =
"/correlationResponse/correlationElement[position()!= 1]">
<sch:assert test = "subjectLevel = 'No'">subjectLevel value
other than first correlationElement must be "No"
.</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
--------------------------------------------------------------------------------
Thanks,
Melkis Penyameen Sathak J
Associate - Projects
Cognizant Technology Solutions
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general