xsl-list
[Top] [All Lists]

grouping where nodes are nested and structure repeats

2005-06-11 02:22:31
Hi,
I would like to group the below xml (bottom of the email) by the "table"
element value. I understand the concept of the Muench method and was
able to construct a stylesheet that grouped the below xml as:
(showing the value of "table" and "level")
 
A:0
  A:1
    A:2
    A:2
 
  B:1
  B:1
 
    C:2
 
But what I was after was something that retained the "parent/child"
relationship between the nodes - thus I wanted:
 
A:0
 
   A:1 <-- first "A" child of A:0 - grouped but the relationship to "it"
and "its" children is retained
      A:2 <-- children of "A:1" grouped
      A:2
      C:2
 
  B:1 <-- second child of A:0 and so on
  B:1
 
The problem I'm running into is that the xsl key function with the
syntax I'm using groups without regard to the parent/child hierachy. 
 
<!-- key function for grouping nodes by table -->
<xsl:key name="entries" match="identifyentry" use="table"/>
 
thus this bit:
 
<xsl:for-each select="identifyentry[generate-id(.) =
generate-id(key('entries',table)[1])]">
  <xsl:sort select="table"/>
   <xsl:for-each select="key('entries',table)">
       ...etc.....
 
Gives me a grouping as listed initially above.  I understand "why" (the
key function is building an index across the occurence of all table
values in the document) - I just don't have the syntactical expertise in
xsl to modify the key or select statement to overcome the problem. 
 
I tried  <xsl:key ........... use="concat(ancestor::table,'+',table)"
but that didn't seem to make any difference. I googled and dug around
but got overwhelmed by the number of different threads out there on
grouping....Anyway, I'm hoping that this is a straightforward problem
and someone has a solution.  Any help much appreciated. Thanx in
advance.
 
-Charlie
 
<identifyentry>
   <level>0</level>
   <table>A</table>
   <children>
        <identifyentry>
           <level>1</level>
           <table>B</table>
        </identifyentry>
        <identifyentry>
            <level>1</level>
           <table>A</table>
           <children>
              <identifyentry>
                <level>2</level>
                <table>A</table>
              </identifyentry>
              <identifyentry>
                  <level>2</level>
                 <table>A</table>
              </identifyentry>
              <identifyentry>
                   <level>2</level>
                   <table>C</table>
               </identifyentry>
          </children>
      </identifyentry>
      <identifyentry>
         <level>1</level>
         <table>B</table>
      </identifyentry>
   </children>

--~------------------------------------------------------------------
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>