complex XPath help need Urgent help

A

Amar

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...
 
M

Martin Honnen

Amar said:
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.

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
 
R

Richard Tobin

<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.
[/QUOTE]
With XPath 1.0 (and 2.0 of course) you can do
/REQUEST/PARAMETERS/PPM[@value]/@value |
/REQUEST[PARAMETERS/PPM[not(@value)]]/RECORD/@_FiledDate

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
 
D

David Carlisle

With XPath 1.0 (and 2.0 of course) you can do
/REQUEST/PARAMETERS/PPM[@value]/@value |
/REQUEST[PARAMETERS/PPM[not(@value)]]/RECORD/@_FiledDate

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
 
R

Richard Tobin

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.
[/QUOTE]
If you can't rely on document order then you can use , rather than |

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

.... but the | works in XPath 1.

-- Richard
 
D

David Carlisle

... but the | works in XPath 1.

-- Richard

ah yes I had it in mind that it was an xpath2 thread but looking back I
see that's not really justified.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top