Compare two dates in XSD 1.1?

This should cover W3C XML Schema, Relax NG and DTD related problems.
Posts: 40

Compare two dates in XSD 1.1?

Wed Mar 08, 2017 12:14 pm

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-renewal-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">
        <Event event-date="2006-05-04T18:13:51.0Z" event-type="INITIAL_REGISTRATION">

So, for example I would like to ensure that all

Code: Select all

values are earlier (less than) the

Code: Select all

, and that

Code: Select all

is always the same as or earlier (less) than

Code: Select all

(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 &lt; ./@content-date"/>

Am I just getting the XPATHs wrong or is there something about the date format maybe?
Posts: 2326

Re: Compare two dates in XSD 1.1?

Mon Mar 13, 2017 7:06 pm


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?

Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests