Click to See Complete Forum and Search --> : Logical XPath expression


rohit72
June 23rd, 2004, 01:06 PM
Hi,
I am having trouble extracting node set of records with unique Codes for each City.

For this I am first getting all the records nodeset for a city and then trying to get unique code nodeset from the city nodeset.

I tried using these XPath expressions.

DAL_OUTPUT/RECORD[(CITY ='NEWYORK')][(not(CODE = preceding-sibling::RECORD/CODE))]


DAL_OUTPUT/RECORD[(CITY ='NEWYORK') and (not(CODE = preceding-sibling::RECORD/CODE))]

I would really appreciate if someone can help me here.

Input xml is something like this:

<DAL_OUTPUT>
<RECORD>
<CITY>NEWYORK</CITY>
<CODE>1778</CODE>
</RECORD>
<RECORD>
<CITY>ATLANTA</CITY>
<CODE>1779</CODE>
</RECORD>
<RECORD>
<CITY>NEWYORK</CITY>
<CODE>1779</CODE>
</RECORD>
<RECORD>
<CITY>NEWYORK</CITY>
<CODE>1778</CODE>
</RECORD>
<RECORD>
<CITY>ATLANTA</CITY>
<CODE>1889</CODE>
</RECORD>
<RECORD>
<CITY>ATLANTA</CITY>
<CODE>1889</CODE>
</RECORD>
</DAL_OUTPUT>

khp
June 24th, 2004, 04:07 AM
I think the problem is that preceding-sibling::RECORD/CODE is the set of all code nodes in the preceding-sibling records, when comparing this against a single node, it should hardly be a surprise, that it doesn't work.
I have to admit I'am not sure how to solve your problem directly in xpath.
I do something simmilar in XSL. But I run an for-each on the records, declare a variable to contain the value of code, inside the for-each. and then use an expression like not(preceding-sibling::RECORD/CODE[string(.)=string($code)])
to check for duplicates.