-
Logical XPath expression
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>
-
I think the problem is that
Code:
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
Code:
not(preceding-sibling::RECORD/CODE[string(.)=string($code)])
to check for duplicates.