complex XPath help need Urgent help

Discussion in 'XML' started by Amar, Nov 28, 2007.

  1. Amar

    Amar Guest

    I have XML Data:
    <REQUEST>
    <PARAMETERS>
    <PPM Name="CCCS Filed Date" value="xxxx"></PPM>
    </PARAMETERS>

    <RECORD _FiledDate="12/15/2003"></RECORD>

    </REQUEST>

    I want to get data from @value {"xxxx"} if exist, otherwise get value
    from @_FiledDate.

    Please help me...
     
    Amar, Nov 28, 2007
    #1
    1. Advertisements

  2. With XPath 2.0 you can do
    if (/REQUEST/PARAMETERS/PPM/@value) then
    /REQUEST/PARAMETERS/PPM/@value else /REQUEST/RECORD/@_FiledDate

    With XPath 1.0 (and 2.0 of course) you can do
    /REQUEST/PARAMETERS/PPM[@value]/@value |
    /REQUEST[PARAMETERS/PPM[not(@value)]]/RECORD/@_FiledDate
     
    Martin Honnen, Nov 29, 2007
    #2
    1. Advertisements

  3. [/QUOTE]
    If the document is as shown, with <PARAMETERS> preceding <RECORD>,
    then

    (/REQUEST/PARAMETERS/PPM/@value|/REQUEST/RECORD/@_FiledDate)[1]

    will do it, because the @value - if it exists - is guaranteed to be
    before the @_FiledDate in document order.

    Martin's is a more general solution.

    -- Richard
     
    Richard Tobin, Nov 29, 2007
    #3
  4. If the document is as shown, with <PARAMETERS> preceding <RECORD>,
    then

    (/REQUEST/PARAMETERS/PPM/@value|/REQUEST/RECORD/@_FiledDate)[1]

    will do it, because the @value - if it exists - is guaranteed to be
    before the @_FiledDate in document order.

    Martin's is a more general solution.

    -- Richard[/QUOTE]

    If you can't rely on document order then you can use , rather than |

    (/REQUEST/PARAMETERS/PPM/@value,/REQUEST/RECORD/@_FiledDate)[1]

    works whatever order these nodes appear in the source.

    (node-which-might-not-exist,'default')[1]

    is (or is going to be) a very common idiom in xpath2.

    David
     
    David Carlisle, Nov 30, 2007
    #4
  5. [/QUOTE]
    .... but the | works in XPath 1.

    -- Richard
     
    Richard Tobin, Nov 30, 2007
    #5
  6. ah yes I had it in mind that it was an xpath2 thread but looking back I
    see that's not really justified.
     
    David Carlisle, Nov 30, 2007
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.