Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Please Help with the Xpath...

Reply
Thread Tools

Please Help with the Xpath...

 
 
supergreat
Guest
Posts: n/a
 
      08-30-2004

Could someone help me with the XPath to select LastName from the below
xml without duplicating the name.
Note: There are two cities in the above tree that have the same
information, I just want to pick one, not the two,
and I want my select to check the two cities and just pick one... Here
is the one I wrote, It pick up two, I just
want one

/Residence/*/City[@id='16']/LastName
'Brown'
'Brown'


<Residence>
<California>
<City active="true" id="16">
<FirstName>James</FirstName>
<LastName>Brown</LastName>
<Phone>(800) 445-4545</Phone>
<Fax>(800) 445-4500</Fax>
</City>
<City active="true" id="17">
<FirstName>James</FirstName>
<LastName>Brown</LastName>
<Phone>(800) 445-4545</Phone>
<Fax>(800) 445-4500</Fax>
</City>
</California>
<Colorado>
<City active="true" id="16">
<FirstName>James</FirstName>
<LastName>Brown</LastName>
<Phone>(800) 445-4545</Phone>
<Fax>(800) 445-4500</Fax>
</City>
<City active="true" id="17">
<FirstName>Mary</FirstName>
<LastName>Bob</LastName>
<Phone>(800) 445-2245</Phone>
<Fax>(800) 445-2200</Fax>
</City>
</Colorado>
</Residence>



--
supergreat
------------------------------------------------------------------------
Posted via http://www.forum4designers.com
------------------------------------------------------------------------
View this thread: http://www.forum4designers.com/message113822.html

 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      08-31-2004
In article <>,
supergreat <> wrote:

[...]
% and I want my select to check the two cities and just pick one... Here
% is the one I wrote, It pick up two, I just
% want one
%
% /Residence/*/City[@id='16']/LastName
% 'Brown'
% 'Brown'

How about

/Residence/*/City[@id='16'][1]/LastName

? That's untested, but it should pick up the first city in the list.
--

Patrick TJ McPhee
East York Canada

 
Reply With Quote
 
 
 
 
Marrow
Guest
Posts: n/a
 
      08-31-2004
Hi,

As a pure XPath expression try something like...

/Residence/*/City[@id='16']/LastName[not(. =
.../../preceding-sibling::*/City[@id = '16']/LastName)]

However, if you are doing this within XSLT then using XPath (and axes) to
obtain distinct values is rarely the most efficient method.

HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator



"supergreat" <> wrote in message
news:...
>
> Could someone help me with the XPath to select LastName from the below
> xml without duplicating the name.
> Note: There are two cities in the above tree that have the same
> information, I just want to pick one, not the two,
> and I want my select to check the two cities and just pick one... Here
> is the one I wrote, It pick up two, I just
> want one
>
> /Residence/*/City[@id='16']/LastName
> 'Brown'
> 'Brown'
>
>
> <Residence>
> <California>
> <City active="true" id="16">
> <FirstName>James</FirstName>
> <LastName>Brown</LastName>
> <Phone>(800) 445-4545</Phone>
> <Fax>(800) 445-4500</Fax>
> </City>
> <City active="true" id="17">
> <FirstName>James</FirstName>
> <LastName>Brown</LastName>
> <Phone>(800) 445-4545</Phone>
> <Fax>(800) 445-4500</Fax>
> </City>
> </California>
> <Colorado>
> <City active="true" id="16">
> <FirstName>James</FirstName>
> <LastName>Brown</LastName>
> <Phone>(800) 445-4545</Phone>
> <Fax>(800) 445-4500</Fax>
> </City>
> <City active="true" id="17">
> <FirstName>Mary</FirstName>
> <LastName>Bob</LastName>
> <Phone>(800) 445-2245</Phone>
> <Fax>(800) 445-2200</Fax>
> </City>
> </Colorado>
> </Residence>
>
>
>
> --
> supergreat
> ------------------------------------------------------------------------
> Posted via http://www.forum4designers.com
> ------------------------------------------------------------------------
> View this thread: http://www.forum4designers.com/message113822.html
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
Console profile for Windows app in VC++ - PLEASE PLEASE PLEASE HELP! MuZZy C++ 7 01-07-2005 08:40 PM
Computer problems please please please help Nick Computer Support 0 06-04-2004 08:49 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57