Michael
Michael

Reputation: 285

XSD 1.1 assert to compare dates

I wrote a number of assertions to compare pairs of dates in XSD 1.1 but none of them work.

Examples:

INPUT

<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>

XSD 1.1 asserts:

<xs:assert id="plausibility-issuance-date-plausibility"
        test="@issuance-date &lt; ./@content-date"/>

and

<xs:assert id="plausibility-file-and-record-timezones"
        test="timezone-from-dateTime(Record/@issuance-date) = timezone-from-dateTime(REcords@content-date)"/>

Having read up on dateTime and timezone representations I'm a little overwhelmed.

Can anyone please tell me:

Upvotes: 2

Views: 711

Answers (1)

sergioFC
sergioFC

Reputation: 6016

Your xs:assert XPATH its not correct because it is assumming that issuance-date and content-date are attributes of the same element, but they are not.

You can use an assert with this sample XPATH to say that "there is no Record with issuance-date greater or equal than its parent content-date":

empty(Record[@issuance-date ge ../@content-date])

Example XSD:

<xs:element name="Records">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Record" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="issuance-date" type="xs:dateTime"/>
                    <xs:attribute name="last-update-date" type="xs:dateTime"/>
                    <xs:attribute name="last-renewal-date" type="xs:dateTime"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="content-date" type="xs:dateTime"/>
        <xs:assert id="plausibility-issuance-date-plausibility" test="empty(Record[@issuance-date ge ../@content-date])"/>
    </xs:complexType>
</xs:element>

Upvotes: 1

Related Questions