SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do you specifiy a date range in an xpath expression?

    i'm trying to get only "/headlines/headline" elements from an xml document which have attributes "startDate" and "endDate" in which the current date falls between them. here's what i have that isn't working correctly:

    Code:
    /headlines/headline[@startDate <= '2002-07-12' and @endDate >= '2002-07-12']
    my date values are stored in the same "yyyy-MM-dd" format, yet this does not work. anyone know why?

  2. #2
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll be on the case in the morning.... must sleeeeeeeeep!
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  3. #3
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To start with, unless you have actually specified the data type for startDate, it's just a string to the XML parser, and so it won't be able to make comparisons of the type you are attempting.

    Assuming for the moment that you are using the Microsoft XML parser, you will need to invoke the Microsoft datatype namespace, and specify that the startDate is of type "date".

    If you are able to turn this attribute into an element, then it is easier to do so, since you can then do this:
    Code:
    <?xml version='1.0'?>
    <?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
      <headlines xml:space="preserve"
             xmlns:dt="urn:schemas-microsoft-com:datatypes">
       <startDate dt:dt="date">2002-07-12</startDate>
       <otherelement>stuff here</otherelement>
      </headlines>
    Otherwise, if you MUST keep it as an attribute, then you have to add the namespace and datatype to your schema.

    Anyway, once the datatype has been defined in this way, you should find yourself able to perform comparions in the way that you desire, although you will need to modify your current XPath expression accordingly if you have indeed turned the attribute into an element.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  4. #4
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any joy with that, CrowDozer?
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  5. #5
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i decided to just return all of them and programaticaly determine which get displayed. which is ok because there won't be a whole lot of results and sometimes i have to display them all anyways.

  6. #6
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok!
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •