dependent values problem in schematron
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 3
- Joined: Mon Dec 04, 2006 6:50 pm
dependent values problem in schematron
Hello,
I am trying to use schematron to validate XML files but I am stuck on a situation that I cannot establish a rule for:
Sample XML:
<parameters>
<parameter>
<name>percentage</name>
<value>89</value>
</parameter>
<parameter>
<name>temperatureF</name>
<value>-274<value>
</parameter>
<parameters>
Rules I want to enforce via schematron:
1. If name = percentage then 0 <= value <= 100
2. If name = temperatureF then -40 <= value <= 40
etc.
The rules are controlled by a dictionarry are there are a lot of possibilities. I can't seem to get around the problem that the condition I want to test depends on the value of an element and the immediate sibling value. Any ideeas would be appreciated. Thank you very much.
I am trying to use schematron to validate XML files but I am stuck on a situation that I cannot establish a rule for:
Sample XML:
<parameters>
<parameter>
<name>percentage</name>
<value>89</value>
</parameter>
<parameter>
<name>temperatureF</name>
<value>-274<value>
</parameter>
<parameters>
Rules I want to enforce via schematron:
1. If name = percentage then 0 <= value <= 100
2. If name = temperatureF then -40 <= value <= 40
etc.
The rules are controlled by a dictionarry are there are a lot of possibilities. I can't seem to get around the problem that the condition I want to test depends on the value of an element and the immediate sibling value. Any ideeas would be appreciated. Thank you very much.
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Post by sorin_ristache »
Hello,
For the parameters element you can use the following XML Schema with embedded Schematron rules. The Schematron rules are selected based on the value of the name element.
Associate the schema with your XML document using the XML Schema tab of the Associate Schema dialog and check the Embedded Schematron rules checkbox.
If there are many values of the name element that you want to check then I think Schematron is not very useful because it takes too much to write manually a Schematron rule for each one. You should check the values with an XSLT stylesheet for example or at the application level.
Regards,
Sorin
For the parameters element you can use the following XML Schema with embedded Schematron rules. The Schematron rules are selected based on the value of the name element.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="parameters">
<xs:annotation>
<xs:appinfo>
<sch:pattern name="Check value interval." xmlns:sch="http://www.ascc.net/xml/schematron">
<sch:rule context="parameter[name='percentage']">
<sch:assert test="value >= 0 and value <= 100">Percentage must be between 0 and 100.</sch:assert>
</sch:rule>
<sch:rule context="parameter[name='temperatureF']">
<sch:assert test="value >= -40 and value <= 40">Temperature must be between -40 and 40.</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:NCName"/>
<xs:element name="value" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
If there are many values of the name element that you want to check then I think Schematron is not very useful because it takes too much to write manually a Schematron rule for each one. You should check the values with an XSLT stylesheet for example or at the application level.
Regards,
Sorin
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service