Filtering on Date Fields in an XCBR

Posted by Admin on 07-Aug-2009 10:07

Hi,

I am trying to use an XCBR to filter messages that are not for 'today'. However, I am finding that although my XPATH expression evaluates correctly in Sonic Workbench using the XPath Expression Evaluator [and in another third party tool], the expression does not work correctly when deployed to a container. Note that the XCBR evaluates other expressions correctly.

The XPath Expression ...

     substring-before(string(/File/Proceeding/Event/@scheduleddatetime), 'T') != substring-before(string(current-date()), '+')

          I.e. if @scheduleddatetime isn't today the expression will evaluate to true. HOWEVER, this appears to be always evaluating to true when deployed since messages always go to the asl.Exit endpoint (see XCBR extract below)

          Corresponding XCBR File Extract:

          <RoutingRule xmlns="*">

          <Description/>

          <DistinctRule>

          <Type>XPath</Type>

          <Arguments>

          <Argument name="expression">substring-before(string(/File/Proceeding/Event/@scheduleddatetime), 'T') != substring-before(string(current-date()), '+')</Argument>

          <Argument name="messagePartID">StanJamesFeed</Argument>

          </Arguments>

          </DistinctRule>

          <Destinations>

          <Destination type="ENDPOINT">

          <Name>asl.Exit</Name>

          </Destination>

          </Destinations>

          </RoutingRule>

Example message part extract ...

<?xml version="1.0" encoding="utf-8" ?>

<!--  Book master document -->

<File>

     <Proceeding>

          <Event scheduleddatetime="2009-08-07T17:30:00" status="On">

               ...

NOTE that the following XPATH expression in the XCBR file works ok:

     /File/Proceeding/Event/@status != 'On'

     Corrsponding XCBR Extract:

          <RoutingRule xmlns="*">

          <Description/>

          <DistinctRule>

          <Type>XPath</Type>

          <Arguments>

          <Argument name="expression">/File/Proceeding/Event/@status != 'On'</Argument>

          <Argument name="messagePartID">StanJamesFeed</Argument>

          </Arguments>

          </DistinctRule>

          <Destinations>

          <Destination type="ENDPOINT">

          <Name>asl.Exit</Name>

          </Destination>

          </Destinations>

          </RoutingRule>

Many thanks for any help.

All Replies

Posted by Bill Wood on 24-Aug-2009 13:05

The problem is the conversion to 'sting(.)'.   This is evaluating based on the settings on the machine.  XPath 2.0 Funcitons have a plethora of methods for dealing with dates and those should be used.  (e.g. get-<>-from-date (for month, day, year)).  See http://www.w3.org/TR/xpath-functions/#durations-dates-times  (in particular Section 10.4 -- Comparison Operators on Duration, Date and Time Values and Section 10.5 Component Extraction Functions on Durations, Dates and Times

Posted by Admin on 25-Aug-2009 06:11

Thanks for your post. You are right that the format of the date string is fully dependent upon the environment. On further analysis, the problem I was having was that on my windows XP machine getDate was returning '25-08-2009+1' whereas on a windows 2003 server it was returning '25-08-2009Z+1'. It is a shame that the format-date, format-dateTime, format-Time functions are only available in XSLT and not in Xpath!

This thread is closed