473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Please Help with the Xpath...


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

Jul 20 '05 #1
2 1149
In article <su***************@mail.forum4designers.com>,
supergreat <su***************@mail.forum4designers.com> 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
pt**@interlog.com
Jul 20 '05 #2
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" <su***************@mail.forum4designers.com> wrote in message
news:su***************@mail.forum4designers.com...

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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
4
by: gfrommer | last post by:
Hello everyone, I've been reading through a bunch of XPath tutorials and am confused by a couple items. First, is it possible to have multiple predicates in my XPath statement. For example, the...
1
by: Kathy Burke | last post by:
I'm trying to figure out how to do an xpath that simply looks for a unique attribute name. For example, select the node where the name attribute is "test1"...regardless of which element. It...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
7
by: Peter Morris [Droopy eyes software] | last post by:
Hi all I need a little help with XSD, here is my XML <data> <brandData> <brandGroups> <brandGroup> <name>Group1</name> </brandGroup>
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
2
by: Joe | last post by:
Hi I am going to receive a dataset downstream and I will not know the the fields number of field relations number of relations So I have to be flexible to take unknown data and be able to...
0
by: Joe | last post by:
Hi Could someone give me a simple explaination of this XSD which is a DataSet with relations The tables are fgFAT,e0,e1,e2,e3 which I have deleted I am trying to make sense of the part below...
4
by: Peter | last post by:
Hi! I am frustrated! I spent a lot of time designing a custom dataset schema (XSD file) using the Dataset designer. In my main form I had created an instance of a typed dataset using that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.