Compare two dates in XSD 1.1?

This should cover W3C XML Schema, Relax NG and DTD related problems.
mhGLEIF
Posts: 43
Joined: Tue Jul 26, 2016 6:31 pm

Compare two dates in XSD 1.1?

Post by mhGLEIF »

I want to write a number of assertions to compare pairs of dates in XSD 1.1 but it's not working.

Can someone help me get started?

Here's a couple of examples:

Code: Select all

<Records content-date="2006-05-04T18:13:51.0Z">

<Record issuance-date="2006-05-04T18:13:51.0Z"
last-update-date="2006-05-04T18:13:51.0Z"
last-renewal-date="2006-05-04T18:13:51.0Z" >
</Record>

<Record issuance-date="2006-05-04T18:13:51.0Z"
last-update-date="2006-05-04T18:13:51.0Z" last-renewal-date="2006-05-04T18:13:51.0Z">
<Event event-date="2006-05-04T18:13:51.0Z" event-type="INITIAL_REGISTRATION">
</Event>
</Record>

</Records>
So, for example I would like to ensure that all

Code: Select all

issuance-date
values are earlier (less than) the

Code: Select all

content-date
, and that

Code: Select all

last-renewal-date
is always the same as or earlier (less) than

Code: Select all

last-update-date
(maybe the last update to the record *was* to renew its registration, but the renewal can't happen *without* an update timestamp.

Here's an example of an assertion in the schema:

Code: Select all

<xs:assert id="plausibility-issuance-date-plausibility"
test="@issuance-date < ./@content-date"/>
Am I just getting the XPATHs wrong or is there something about the date format maybe?
adrian
Posts: 2854
Joined: Tue May 17, 2005 4:01 pm

Re: Compare two dates in XSD 1.1?

Post by adrian »

Hi,

The problem is not that they are dates, the problem is in what context you place the assert and what XPath you can use in that context.
AFAIK, you can't use XPath to look outside of the branch (up the hierarchy) you are in. So, if you place the assert within an element or type, you can't use XPath to point to an ancestor of that element or type, you can only point to it and its children.

So where is your assert placed?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply