Search the web
Sign In
New User? Sign Up
xrules · XRules & DynamicDOM
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
How to do sibling checks? non-string compares?   Message List  
Reply | Forward Message #40 of 74 |
RE: [xrules] How to do sibling checks? non-string compares?

Answers interleaved:

 

 

> Rule: Within a leg, departures occur after arrivals, if there are
> arrivals and departures. I see how to validate that, so long as a
> string compare works. Something like: <xr:validate test="depart >
> arrive" /> I'm not sure how the missing arrival or departure affects
> that.

Your rule is correct except that, unfortunately, XPath does not do string comparison; it tries to convert the values to numbers first. But, there is a workaround. Modify your rule slightly to remove the non-numeric characters as follows (also note that I used the ruleset context to enforce the rule on all legs but the first and last):

 

  <xr:ruleset context="/schedule/leg[position() &gt; 1 and position() &lt; last()]">

    <xr:validate test="translate(depart,':','') &gt; translate(arrive,':','')" />

  </xr:ruleset>

 

If the arrival or departure is missing, the rule will fail, which will serve to validate that both nodes exist. If you want a specific error message when a node is missing, you can add a separate rule to validate for this condition.

 

 

 

> Rule: For any leg, the arrival is after the previous leg's departue.

For this use the XPath expression preceding-sibling::leg[1] to get the preceding sibling. Also, note that I changed the ruleset context to enforce the rule on all nodes except the first.

 

  <xr:ruleset context="/schedule/leg[position() &gt; 1]">

    <xr:validate test="translate(arrive,':','') &gt; translate(preceding-sibling::leg[1]/depart,':','')" />

  </xr:ruleset>

 

 

 

> Rule: For the first leg, there is no arrival.
> Rule: For the last leg, there is no departure.

This one is straight forward:

 

  <xr:ruleset context="/schedule">

    <xr:validate test="not(leg[1]/arrive)" />

    <xr:validate test="not(leg[last()]/depart)" />

  </xr:ruleset>

 

 

 

> Rule: All legs except first and last have both an arrival and a departure.

This is satisfied by the first ruleset above. However, for an explicit check you can the following to the first ruleset:

 

    <xr:validate test="boolean(arrive)" />

    <xr:validate test="boolean(depart)" />

 

 

 

> How to do comparisons if the time were expressed in a manner not
> easily compared as strings, e.g. "
1/30/2006 08:00"?

Not easy. XPath doesn’t recognize a date/time type. I’d recommend using the standard XML format for dates: 2006-01-30T08:00. This is the ‘standard’ way for dates in XML, and with it you can use the translate() trick to remove the -, T, and : and perform date comparisons.

 

So, your complete XRules document will look like this:

 

 

 

<xr:rules xmlns:xr="http://www.xrules.org/2003/11">

 

  <xr:ruleset context="/schedule/leg[position() &gt; 1 and position() &lt; last()]">

    <xr:validate test="translate(depart,':','') &gt; translate(arrive,':','')" />

    <xr:validate test="boolean(arrive)" />

    <xr:validate test="boolean(depart)" />

  </xr:ruleset>

 

  <xr:ruleset context="/schedule/leg[position() &gt; 1]">

    <xr:validate test="translate(arrive,':','') &gt; translate(preceding-sibling::leg[1]/depart,':','')" />

  </xr:ruleset>

 

  <xr:ruleset context="/schedule">

    <xr:validate test="not(leg[1]/arrive)" />

    <xr:validate test="not(leg[last()]/depart)" />

  </xr:ruleset>

 

</xr:rules>

 

 

 

Regards,

Waleed

 

 

 

 

 

 

 

-----Original Message-----
From: xrules@yahoogroups.com [mailto:xrules@yahoogroups.com] On Behalf Of johnbrockus
Sent:
Friday, September 15, 2006 10:14 AM
To: xrules@yahoogroups.com
Subject: [xrules] How to do sibling checks? non-string compares?

 

Imagine a truck delivery schedule. Suppose xml is:

...
<schedule>
<leg>
<depart>
08:00</depart>
</leg>
<leg>
<arrive>08:45</arrive>
<depart>10:00</depart>
</leg>
<leg>
<arrive>11:45</arrive>
<depart>13:00</depart>
</leg>
<leg>
<arrive>13:45</arrive>
</leg>
</schedule>
...

Rule: Within a leg, departures occur after arrivals, if there are
arrivals and departures. I see how to validate that, so long as a
string compare works. Something like: <xr:validate test="depart >
arrive" /> I'm not sure how the missing arrival or departure affects
that.

Rule: For any leg, the arrival is after the previous leg's departue.

Rule: For the first leg, there is no arrival.

Rule: For the last leg, there is no departure.

Rule: All legs except first and last have both an arrival and a departure.

2 questions:

How is best to express these rules?

How to do comparisons if the time were expressed in a manner not
easily compared as strings, e.g. "1/30/2006 08:00"?

Thanks.



Sat Sep 16, 2006 5:15 pm

waleed_ka
Offline Offline
Send Email Send Email

Forward
Message #40 of 74 |
Expand Messages Author Sort by Date

Imagine a truck delivery schedule. Suppose xml is: ... <schedule> <leg> <depart>08:00</depart> </leg> <leg> <arrive>08:45</arrive> <depart>10:00</depart> ...
johnbrockus
Offline Send Email
Sep 16, 2006
4:14 pm

... Your rule is correct except that, unfortunately, XPath does not do string comparison; it tries to convert the values to numbers first. But, there is a...
Waleed K. Abdulla
waleed_ka
Offline Send Email
Sep 16, 2006
5:34 pm

... XPath 1.0 is limited to this, XPath 2.0 supports the 19 primitive types defined by XML Schema. I believe the only XPath 2.0 implementation for .NET is...
David Carver
d_a_carver
Offline Send Email
Sep 17, 2006
1:57 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help