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

grouping where nodes are nested and structure repeats

Subject: grouping where nodes are nested and structure repeats
From: "Charles Macleod" <cmacleod@xxxxxxxx>
Date: Sat, 11 Jun 2005 02:22:31 -0700
charles macleod
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>

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.