Validating a duration

Robert Leftwich <[email protected]> Mon, 28 Jul 2003 10:36:07 +1000
Newsgroups gmane.text.xml.schematron
Message-ID <[email protected]>
I am having difficulty writing a Schematron validation for a duration. The 
(simplified) XML is as follows:

<entry>
     <start-date>20030726</start-date>
      <start-time>13:00</start-time>
      <end-time>15:30</end-time>
      <duration>
          <hours>2</hours>
          <minutes>30</minutes>
      </duration>
</entry>

I need to validate that the duration hours and minutes are correct and this 
is relatively easily achieved (see below) for all but the edge case where 
the end-time is at midnight, i.e. 00:00

<sch:let name="currentStartTimeSecs" value="number(substring(start-time, 
1,2))*60 + number(substring(start-time,4,2))"/>
<sch:let name="currentEndTimeSecs" value="number(substring(end-time, 
1,2))*60 + number(substring(end-time,4,2))"/>
<sch:let name="currentCalculatedDurationSecs" value="$currentEndTimeSecs - 
$currentStartTimeSecs"/>

<sch:assert test="$currentCalculatedDurationSecs =
                                  (number(normalize-space(duration/hours))*60 
+ number(normalize-space(duration/minutes)))"/>

Is there any way to detect that the end-time is 00:00 and adjust the 
currentEndTimeSecs accordingly ?

Robert




-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01