Validating dates in schematron
Having trouble installing Oxygen? Got a bug to report? Post it all here.
Validating dates in schematron
Hi,
I need to validate the following using schematron: date B must be at 1 day earlier than date A:
Valid XML:
Not valid XML:
I created the following rule comparing the two dates:
but I'm not sure how to say "one day earlier". Do I need to convert the date into number or is there a way to do it directly from the date type in XSLT2?
Thanks in advance,
Ewa
I need to validate the following using schematron: date B must be at 1 day earlier than date A:
Valid XML:
Code: Select all
<dateA>2011-05-11</dateA>
<dateB>2011-05-10</dateB>
Code: Select all
<dateA>2011-05-11</dateA>
<dateB>2011-05-11</dateB>
Code: Select all
<sch:rule context="//dateB">
<sch:assert test="(.) < dateA">ERROR</sch:assert>
</sch:rule>
Thanks in advance,
Ewa
Re: Validating dates in schematron
Hello,
You can convert to 'xs:date' and compare the dates. To obtain the dateA you need to get the previous sibling using the following XPath 'preceding-sibling::dateA[1]', and then decrease one day to obtain the expected date. You can provide also a fix that will correct the current date. The Schematron file can be something like this:
Best Regards,
Octavian
You can convert to 'xs:date' and compare the dates. To obtain the dateA you need to get the previous sibling using the following XPath 'preceding-sibling::dateA[1]', and then decrease one day to obtain the expected date. You can provide also a fix that will correct the current date. The Schematron file can be something like this:
Code: Select all
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
<sch:pattern>
<sch:rule context="dateB">
<sch:let name="dateA" value="xs:date(preceding-sibling::dateA[1])"/>
<sch:let name="expectedDate" value="$dateA - xs:dayTimeDuration('P1D')"/>
<sch:assert test="xs:date(.) = $expectedDate" sqf:fix="setDateB">
ERROR The current date '<sch:value-of select="."/>' should be one day earlier than date A '<sch:value-of select="$dateA"/>' </sch:assert>
<sqf:fix id="setDateB">
<sqf:description>
<sqf:title>Set current date to '<sch:value-of select="$expectedDate"/>'</sqf:title>
</sqf:description>
<sqf:replace match="text()" select="$expectedDate">
</sqf:replace>
</sqf:fix>
</sch:rule>
</sch:pattern>
</sch:schema>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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