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

RE: XML Group with XSL

Subject: RE: XML Group with XSL
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 23 Apr 2004 07:59:06 +0100
group by xsl
I find your choice of element names makes my eyes go spotty, but it looks to
me as if you are trying to merge two nodes if the names and ID attributes of
all their ancestors are identical. In other words, you have a standard
grouping problem, in which the grouping key is the concatenation of the
names and ID attribute of all the ancestors.

I would suggest a two stage transformation. First create a flat structure in
which all the nodes to be grouped are at the same level, and in which there
is an extra attribute containing the concatenation of the values that make
up this grouping key (use <xsl:for-each select="ancestor::*">). Then do a
standard Muenchian grouping to eliminate the duplicates.

Michael Kay 

> -----Original Message-----
> From: aalikaj@xxxxxxxxxxxx [mailto:aalikaj@xxxxxxxxxxxx] 
> Sent: 22 April 2004 14:20
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  XML Group with XSL
> 
> 
> Hi All,
> 
> I'm still trying to solve my problem.
> 
> In a few words, i'm trying to explain my problem again.
> 
> I have an XML file with this format:
> 
> <ROOT>
>       <NODE1 ID = "1">
>             <NODE1_1_A ID="1">
>                   <NODE1_1_1_A ID = "1">
>                         <NODE1_1_1_1_A ID = "1">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "2">
>                               data
>                         </NODE1_1_1_1_A>
>                   </NODE1_1_1_A>
>                   <NODE1_1_1_A ID = "2">
>                         <NODE1_1_1_1_A ID = "1">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "2">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "3">
>                               data
>                         </NODE1_1_1_1_A>
> 
>                   </NODE1_1_1_A>
> 
>             </NODE1_1_A>
> 
>             <NODE1_1_A ID="2">
>                   <NODE1_1_1_A ID = "1">
>                         <NODE1_1_1_1_A ID = "1">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "2">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "3">
>                               data
>                         </NODE1_1_1_1_A>
> 
>                   </NODE1_1_1_A>
> 
>             </NODE1_1_A>
>       </NODE1>
>       <NODE1 ID = "1">
>             <NODE1_1_A ID="1">
> 
>                   <NODE1_1_1_A ID = "1">
>                         <NODE1_1_1_1_B ID = "1">
>                               data
>                         </NODE1_1_1_1_B>
>                         <NODE1_1_1_1_B ID = "2">
>                               data
>                         </NODE1_1_1_1_B>
>                         <NODE1_1_1_1_B ID = "3">
>                               data
>                         </NODE1_1_1_1_B>
> 
>                   </NODE1_1_1_A>
> 
>             </NODE1_1_A>
>       </NODE1>
>       <NODE1 ID = "1">
>             <NODE1_1_A ID="1">
> 
>                   <NODE1_1_1_B ID = "1">
>                         DATA
>                   </NODE1_1_1_B>
>                   <NODE1_1_1_B ID = "2">
>                         DATA
>                   </NODE1_1_1_B>
> 
>                   <NODE1_1_1_B ID = "3">
>                         DATA
>                   </NODE1_1_1_B>
> 
>             </NODE1_1_A>
>       </NODE1>
> 
>       <NODE1 ID = "1">
>             <NODE1_1_B ID="1">
>                   DATA
>             </NODE1_1_B>
>             <NODE1_1_B ID="2">
>                   DATA
>             </NODE1_1_B>
>             <NODE1_1_B ID="3">
>                   DATA
>             </NODE1_1_B>
>             <NODE1_1_B ID="3">
>                   DATA
>             </NODE1_1_B>
>       </NODE1>
> </ROOT>
> 
> As you can see, the same node, with the same attributes, 
> apears more than
> once, so i want to collapse them. I want the following output
> 
> <ROOT>
>       <NODE1 ID = "1">
>             <NODE1_1_A ID="1">
>                   <NODE1_1_1_A ID = "1">
>                         <NODE1_1_1_1_A ID = "1">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "2">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_B ID = "1">
>                               data
>                         </NODE1_1_1_1_B>
>                         <NODE1_1_1_1_B ID = "2">
>                               data
>                         </NODE1_1_1_1_B>
>                         <NODE1_1_1_1_B ID = "3">
>                               data
>                         </NODE1_1_1_1_B>
>                   </NODE1_1_1_A>
>                   <NODE1_1_1_A ID = "2">
>                         <NODE1_1_1_1_A ID = "1">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "2">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "3">
>                               data
>                         </NODE1_1_1_1_A>
> 
>                   </NODE1_1_1_A>
>                   <NODE1_1_1_B ID = "1">
>                         DATA
>                   </NODE1_1_1_B>
>                   <NODE1_1_1_B ID = "2">
>                         DATA
>                   </NODE1_1_1_B>
> 
>                   <NODE1_1_1_B ID = "3">
>                         DATA
>                   </NODE1_1_1_B>
> 
>             </NODE1_1_A>
> 
>             <NODE1_1_A ID="2">
>                   <NODE1_1_1_A ID = "1">
>                         <NODE1_1_1_1_A ID = "1">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "2">
>                               data
>                         </NODE1_1_1_1_A>
>                         <NODE1_1_1_1_A ID = "3">
>                               data
>                         </NODE1_1_1_1_A>
>                   </NODE1_1_1_A>
>             </NODE1_1_A>
> 
>             <NODE1_1_B ID="1">
>                   DATA
>             </NODE1_1_B>
>             <NODE1_1_B ID="2">
>                   DATA
>             </NODE1_1_B>
>             <NODE1_1_B ID="3">
>                   DATA
>             </NODE1_1_B>
>             <NODE1_1_B ID="3">
>                   DATA
>             </NODE1_1_B>
>       </NODE1>
> </ROOT>
> 
> I Can do this with DOM, but I want to use XSL if this is possible.
> 
> Thank you
> 
> Ardian Alikaj
> Software Developer
> Ntuitive Software & Systems.
> E: aalikaj@xxxxxxxxxxxx
> T: 416.863.9566 x326
> F: 416.863.8919
> 
> 
>                                                               
>                                                               
>           
>                       "Michael Kay"                           
>                                                               
>           
>                       <mhk@xxxxxxxxx>          To:       
> <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                             
>                
>                                                cc:            
>                                                               
>           
>                       04/21/2004 06:31         Subject:  RE: 
>  XML Group with XSL                                      
>            
>                       PM                                      
>                                                               
>           
>                       Please respond to                       
>                                                               
>           
>                       xsl-list                                
>                                                               
>           
>                                                               
>                                                               
>           
>                                                               
>                                                               
>           
> 
> 
> 
> 
> > How can I exclude the node_1 from the following code
> > <xsl:template match="node_1">
> >              <xsl:copy-of select="."/>
> > </xsl:template>
> >
> > It prints out node_1 with its children. I want only 
> children elements,
> > because "node_1" has been prented once
> 
> Use <xsl:copy select="*">.
> 
> Michael Kay

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.