xpath question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sam

    xpath question

    I use in my csharp code this xml:
    <doc>
    <item Id="1">
    <item>1</item>
    </item>
    <item Id="1">
    <item>2</item>
    </item>
    <item Id="2">
    <item>A</item>
    </item>
    <item Id="3">
    <item>B</item>
    </item>
    </doc>
    And I need to exclude all items that Id="1" and then in the result set, get
    the a range of nodes, for exmpale the first to third nodes.
    I use this /doc/item[@Id != "1" and (position() >0 and position() <= 2) ]
    but there is no result, why ?


    Thanks for help.
    Sam

  • Bjoern Hoehrmann

    #2
    Re: xpath question

    * sam wrote in microsoft.publi c.dotnet.xml:
    >I use in my csharp code this xml:
    ><doc>
    ><item Id="1">
    <item>1</item>
    ></item>
    ><item Id="1">
    <item>2</item>
    ></item>
    ><item Id="2">
    <item>A</item>
    ></item>
    ><item Id="3">
    <item>B</item>
    ></item>
    ></doc>
    >And I need to exclude all items that Id="1" and then in the result set, get
    >the a range of nodes, for exmpale the first to third nodes.
    >I use this /doc/item[@Id != "1" and (position() >0 and position() <= 2) ]
    >but there is no result, why ?
    Because you are trying to further filter a node set that does not exist.
    The predicate you specify above evaluates the three conditions at once,
    and there are no elements matching all three conditions. You will have
    to use multiple predicates. http://www.w3.org/TR/xpath#location-paths
    has good examples.
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

    Comment

    • George Bina

      #3
      Re: xpath question

      /doc/item[@Id != "1"] [ (position() >0 and position() <= 2) ]

      Regards,
      George
      ---------------------------------------------------------------------
      George Cristian Bina - http://aboutxml.blogspot.com/
      <oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger


      Comment

      Working...