xsl-list
[Top] [All Lists]

RE: XML Group with XSL

2004-04-22 23:59:06
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(_at_)ntuitive(_dot_)com 
[mailto:aalikaj(_at_)ntuitive(_dot_)com] 
Sent: 22 April 2004 14:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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(_at_)ntuitive(_dot_)com
T: 416.863.9566 x326
F: 416.863.8919


                                                              
                                                              
          
                      "Michael Kay"                           
                                                              
          
                      <mhk(_at_)mhk(_dot_)me(_dot_)uk>          To:       
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>                            
 
               
                                               cc:            
                                                              
          
                      04/21/2004 06:31         Subject:  RE: 
[xsl] 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


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--







--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





<Prev in Thread] Current Thread [Next in Thread>