xsl-list
[Top] [All Lists]

Re: [xsl] XPath expression that generates false plus a message?

2011-04-25 15:52:08

I used the XPath expression within the new XML Schema 1.1<assert>  element:

     <xs:element name="meeting">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="start" type="xs:time" />
                 <xs:element name="end" type="xs:time" />
             </xs:sequence>
             <xs:assert test="if (xs:time(start) gt xs:time(end)) then
                                                      true()
                                                else
                                                       trace(false(), 'Hey, the meeting 
ends before it begins!')" />
         </xs:complexType>
     </xs:element>

Here is a<meeting>  with bad data:

<meeting>
      <start>10:00:00</start>
      <end>09:00:00</end>
</meeting>


Your assertion is true if the start time is greater than the end time. Which is the case for your "bad" data.

(Note also that comparing times is an error-prone business: what happens if you have a meeting that starts at 23:00 and finishes at 01:00?)

Michael Kay
Saxonica



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>