XPath: Multiple conditions (contains, dates, node-set)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jorgedelgadolopez@gmail.com

    XPath: Multiple conditions (contains, dates, node-set)

    Hi all,

    I am using the xpathnavigator evaluate function on .net (xpath 1
    right?). Now I need to expand the code to do multiple contains,
    compare dates (such as 'before', 'between' and 'after'), and so on.

    This is the thought:

    //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))
    and before(@birthda te, '1980-01-01')]

    How can I accomplish this? there are problems if the results of a
    condition is a node-set or not I suppose. Every condition is generated
    and added to the expression, the problem is that it MUST be one
    expression, since I need to read it and load my controls with the
    condition.

    My UI looks like:
    DropDown with the attributes
    DropDown with some functions (contains, etc)
    Textboxes for the strings/dates to compare the attributes with

    What I am trying to accomplish is "refine your search" functionality,
    or in other words "Live filters" where if the XML is changed, the
    xpath is run and the view is updated.

    Any ideas on how to do this using XPath/XQuery and .NET?

    Thanks!
    / jorge

  • Martin Honnen

    #2
    Re: XPath: Multiple conditions (contains, dates, node-set)

    jorgedelgadolop ez@gmail.com wrote:
    I am using the xpathnavigator evaluate function on .net (xpath 1
    right?). Now I need to expand the code to do multiple contains,
    compare dates (such as 'before', 'between' and 'after'), and so on.
    >
    This is the thought:
    >
    //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))
    and before(@birthda te, '1980-01-01')]
    There is no before function in XPath 1.0. There is <, <=, >, >=
    comparison in XPath 1.0 but only for numbers so you can compare dates in
    the form yyyy-mm-dd using
    number(translat e(@birthdate, '-', '')) <
    number(translat e('1980-01-01'), '-', '')



    --

    Martin Honnen --- MVP XML

    Comment

    • jorgedelgadolopez@gmail.com

      #3
      Re: XPath: Multiple conditions (contains, dates, node-set)

      Yes, XPath1 does not have support for dates, which means having to
      compare the parts of a date as integers. the "before" example was just
      to make the point. But thanks for the reply.

      The actual problem has to do more with the " and " operator between
      all the conditions, if the first one returns a node-set and so on.

      / jorge

      On 3 Aug, 12:19, Martin Honnen <mahotr...@yaho o.dewrote:
      jorgedelgadolo. ..@gmail.com wrote:
      I am using the xpathnavigator evaluate function on .net (xpath 1
      right?). Now I need to expand the code to do multiple contains,
      compare dates (such as 'before', 'between' and 'after'), and so on.
      >
      This is the thought:
      >
      //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))
      and before(@birthda te, '1980-01-01')]
      >
      There is no before function in XPath 1.0. There is <, <=, >, >=
      comparison in XPath 1.0 but only for numbers so you can compare dates in
      the form yyyy-mm-dd using
      number(translat e(@birthdate, '-', '')) <
      number(translat e('1980-01-01'), '-', '')
      >
      --
      >
      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      • Martin Honnen

        #4
        Re: XPath: Multiple conditions (contains, dates, node-set)

        jorgedelgadolop ez@gmail.com wrote:
        The actual problem has to do more with the " and " operator between
        all the conditions, if the first one returns a node-set and so on.
        I am not sure what you are asking about. It is certainly possible to use
        e.g.
        element1[element2 and @attr1 = 'value 1']

        --

        Martin Honnen --- MVP XML

        Comment

        • Dimitre Novatchev

          #5
          Re: XPath: Multiple conditions (contains, dates, node-set)

          The actual problem has to do more with the " and " operator between
          all the conditions, if the first one returns a node-set and so on.
          Actually, there is *no* problem with this.

          The XPath expression:

          //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))

          will select all "person" elements whose "name" attribute contains the string
          "george" and does not contain the string "bush".

          Where do you see a problem?


          Cheers,
          Dimitre Novatchev

          P.S. I recommend using the XPath Visuaizer for learning XPath the fun way --
          in case there is any doubt how an XPath expression will be evaluated, just
          use the XPath Visualizer to see.


          <jorgedelgadolo pez@gmail.comwr ote in message
          news:1186237189 .942808.293260@ w3g2000hsg.goog legroups.com...
          Yes, XPath1 does not have support for dates, which means having to
          compare the parts of a date as integers. the "before" example was just
          to make the point. But thanks for the reply.
          >
          The actual problem has to do more with the " and " operator between
          all the conditions, if the first one returns a node-set and so on.
          >
          / jorge
          >
          On 3 Aug, 12:19, Martin Honnen <mahotr...@yaho o.dewrote:
          >jorgedelgadolo ...@gmail.com wrote:
          I am using the xpathnavigator evaluate function on .net (xpath 1
          right?). Now I need to expand the code to do multiple contains,
          compare dates (such as 'before', 'between' and 'after'), and so on.
          >>
          This is the thought:
          >>
          //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))
          and before(@birthda te, '1980-01-01')]
          >>
          >There is no before function in XPath 1.0. There is <, <=, >, >=
          >comparison in XPath 1.0 but only for numbers so you can compare dates in
          >the form yyyy-mm-dd using
          > number(translat e(@birthdate, '-', '')) <
          >number(transla te('1980-01-01'), '-', '')
          >>
          >--
          >>
          > Martin Honnen --- MVP XML
          > http://JavaScript.FAQTs.com/
          >
          >

          Comment

          • jorgedelgadolopez@gmail.com

            #6
            Re: XPath: Multiple conditions (contains, dates, node-set)

            Well, so it seems that it works, I skipped the dates for now. Very
            strange, I wasnt getting the correct results on the expression i had
            created. but a few tweaks and now it works fine. I wonder what it was,
            the first condition returned a node-set and the next one didnt operate
            on that node-set. oh well. it works now..

            thanks Dimitre
            / jorge

            On 4 Aug, 15:19, "Dimitre Novatchev" <dimit...@tpg.c om.auwrote:
            The actual problem has to do more with the " and " operator between
            all the conditions, if the first one returns a node-set and so on.
            >
            Actually, there is *no* problem with this.
            >
            The XPath expression:
            >
            //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))
            >
            will select all "person" elements whose "name" attribute contains the string
            "george" and does not contain the string "bush".
            >
            Where do you see a problem?
            >
            Cheers,
            Dimitre Novatchev
            >
            P.S. I recommend using the XPath Visuaizer for learning XPath the fun way --
            in case there is any doubt how an XPath expression will be evaluated, just
            use the XPath Visualizer to see.
            >
            <jorgedelgadolo ...@gmail.comwr ote in message
            >
            news:1186237189 .942808.293260@ w3g2000hsg.goog legroups.com...
            >
            Yes, XPath1 does not have support for dates, which means having to
            compare the parts of a date as integers. the "before" example was just
            to make the point. But thanks for the reply.
            >
            The actual problem has to do more with the " and " operator between
            all the conditions, if the first one returns a node-set and so on.
            >
            / jorge
            >
            On 3 Aug, 12:19, Martin Honnen <mahotr...@yaho o.dewrote:
            jorgedelgadolo. ..@gmail.com wrote:
            I am using the xpathnavigator evaluate function on .net (xpath 1
            right?). Now I need to expand the code to do multiple contains,
            compare dates (such as 'before', 'between' and 'after'), and so on.
            >
            This is the thought:
            >
            //person[contains(@name, 'george') and not(contains(@n ame, 'bush'))
            and before(@birthda te, '1980-01-01')]
            >
            There is no before function in XPath 1.0. There is <, <=, >, >=
            comparison in XPath 1.0 but only for numbers so you can compare dates in
            the form yyyy-mm-dd using
            number(translat e(@birthdate, '-', '')) <
            number(translat e('1980-01-01'), '-', '')
            >
            --
            >
            Martin Honnen --- MVP XML
            http://JavaScript.FAQTs.com/

            Comment

            Working...