CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    1

    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>

  2. #2
    Join Date
    May 2003
    Location
    Denmark
    Posts
    1,315
    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.
    The biggest problem encountered while trying to design a system that was completely foolproof,
    was, that people tended to underestimate the ingenuity of complete fools.
    Douglas Adams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured