Re: [xsl] attributes and nodes

Subject: Re: [xsl] attributes and nodes
From: Oleg Tkachenko <olegt@xxxxxxxxxxxxx>
Date: Mon, 21 Apr 2003 16:18:11 +0300
Evgenia Firsova wrote:

I have xml:
<AddressCountryList>
	<Country ID="1" DepartID="8" Name="countryname">
		<City Nick="nickname1" Mail="mail" AddressID="1">
			<PhoneList>
				<Phone Num="pnone"/>
			</PhoneList>
		</City>
		<City Nick="nickname2" Mail="mail" AddressID="3">
			<PhoneList>
				<Phone Num="phone"/>
			</PhoneList>
		</City>
	</Country>
	...
</AddressCountryList>

I need an XPATH, which matched Country with _all_ it's attributes and _some_ childrens.
Something like //AddressCountryList/Country/@*|City[@Nick='nickname1']


The result I need is:

<AddressCountryList>
	<Country ID="1" DepartID="8" Name="countryname">
		<City Nick="nickname1" Mail="mail" AddressID="1">
			<PhoneList>
				<Phone Num="pnone"/>
			</PhoneList>
		</City>
	</Country>
	...
</AddressCountryList>

This task should be done with only one XPATH because I'll use it not in xslt, ubt on other script language.

I doubt it can be done with a single XPath exression. Ok, you can select Country attributes and some its children City elements, but how do you build result tree from such unordered nodeset?
And in your desired result there is also AddressCountryList, which is out of your selection...
I'd suggest you another approach - select all Country elements and iterate over copying them with all attributes and some children City elements.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread