[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Searching in Sub-children from an Array

Subject: Re: Searching in Sub-children from an Array
From: Ronan Klyne <ronan.klyne@xxxxxxxxxxx>
Date: Wed, 14 Feb 2007 16:58:44 +0000
Re:  Searching in Sub-children from an Array
Houman Khorasani wrote:
> Hello Everyone,
> 
> A while ago I have asked about the lovely Muenchian method to solve a
> simple example.  Unfortunately I am stuck with something that should be
> straight forward.  I greatly would appreciate any input on this:
> 
> 
> XML Input:
> 
> <tree>
> 	<fruit ID="111">
> 		<mango ID="333">
> 			<colour>
> 				<Rate_Structure_Event
> ConceptType="Rate_Structure_Event" ID="1"></Rate_Structure_Event>
> 			</colour>
> 		</mango>
> 		<orange ID="222">
> 			<color>orange</color>
> 		</orange>
> 	</fruit>
> 	<fruit_adjustment>
> 		<color>
> 			<Path>
> 				<Steps>111,333</Steps>			
> 			</Path>
> 			<bla>false</bla>
> 			<Rate_Event ConceptType="Rate_Event"
> ID="A"></Rate_Event>
> 			<Rate_Event ConceptType="Rate_Event"
> ID="B"></Rate_Event>
> 		</color>		
> 	</fruit_adjustment>
> </tree>
> 
> 
> 
> XSLT 2.0:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	
> 	<xsl:key name="step" match="fruit_adjustment/color//Rate_Event"
> use="../Path/Steps"/>
> 	
> 	<xsl:template match="*">
> 		<xsl:copy>
> 			<xsl:copy-of select="@*"/>
> 			<xsl:apply-templates/>
> 		</xsl:copy>
> 	</xsl:template>
> 	
> 	<xsl:template match="fruit_adjustment"/>
> 	
> 	<xsl:template match="colour">
> 		<xsl:copy-of
> select="(key('step',string-join(ancestor-or-self::*[@ID]/@ID,',')),.)[1]
> "/>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> 
> 
> My desired XML output:
> 
> <tree>
> 	<fruit ID="111">
> 		<mango ID="333">
> 			<Rate_Event ConceptType="Rate_Event"
> ID="A"></Rate_Event>
> 			<Rate_Event ConceptType="Rate_Event"
> ID="B"></Rate_Event>
> 		</mango>
> 		<orange ID="222">
> 			<color>orange</color>
> 		</orange>
> 	</fruit>
> </tree>
> 
> 
> 
> However I get this XML Output, what do I do wrong? (Only one Rate_Event
> is being copied over, why?)
> 
> <tree>
> 	<fruit ID="111">
> 		<mango ID="333">
> 			<Rate_Event ConceptType="Rate_Event" ID="A"/>
> 		</mango>
> 		<orange ID="222">
> 			<color>orange</color>
> 		</orange>
> 	</fruit>
> </tree>
> 
> I greatly appreciate your help,
> Kind Regards
> Houman
> 
> 

I believe the problem is in this line:
<xsl:copy-of
select="(key('step',string-join(ancestor-or-self::*[@ID]/@ID,',')),.)[1]"/>

The section reading
'(key('step',string-join(ancestor-or-self::*[@ID]/@ID,',')),.)' will
select all matching Rate_Event nodes correctly, as well as the current
node. The predicate at the end '[1]', will then take the first item in
this list. I suspect you want to use some kind of conditional here...

	# r

-- 
Ronan Klyne
Business Collaborator Developer
Tel: +44 (0)870 163 2555
ronan.klyne@xxxxxxxxxxx
www.groupbc.com

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.