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

RE: [xsl] xslt for hierarchical data

  • To: <xml-dev@l...>
  • Subject: RE: [xsl] xslt for hierarchical data
  • From: Jody Robert Ford <jody.r.ford@g...>
  • Date: Tue, 7 Feb 2006 20:14:00 -0500
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:to:subject:date:mime-version:content-type:x-mailer:x-mimeole:thread-index:from:message-id; b=cxtxRgBl/yuEuocCLaWNu+75z82eC+f5pSfscXt/WzjE7HnazPk3x57ZbyN4ZFG1v1gt/Eh7URZRU+aFNrvl4VOBsNCKn13eR2mmXo7i8d1eS2k4Kvcpz9jVnJ3fEDCneDg+gPh8BukQnGvfeul6tIYBoqjjmOR6Sl8/b2SnGIY=
  • Thread-index: AcYrV/dul58v24m+R/a/I7+IBGKsuwA9OqKA

xsl hierarchical


Thanks for the help.  But I still have 2 problems.
 
1.  The logical root must be dynamic. It isn't always "Jack"  The example provided hardcoded jack as root 0.
2.  I need to know, for display purposes, if the node has any children.
 
somethinng like this:
 
<node>
  <node>Jack, 0,true<node>
  <node>
     <name>Jack Jr, 1, true</name>
     <node>
        <name>William, 4, true</name>
        <node>
           <name>William Jr., 7, true</name>
           <node>
              <name>William III, 9, true</name>
              <node>
                 <name>William IV, 11, false</name>
              </node>
           </node>
        </node>
     </node>
     <node>
        <name>Jack III, 3, false</name>
     </node>
  </node>
</node>

And, truthfully, I'm trying to format the display to work like this:
http://www.codeproject.com/jscript/dhtml_treeview.asp
 

Can anyone help?  I'm a but of a time crunch - as always.

 

thanks again,


-jody

 

On 1/11/06, andrew welch <andrew.j.welch@g...> wrote:

On 1/11/06, Jody Robert Ford <jody.r.ford@g...> wrote:
> Given a data structure:
>
>
>
> <record id=1 parent="Jack" parentid=0>Jack Jr</record>
>
> <record id=4 parent="Jack" parentid=1>William</record>
>
> <record id=3 parent="Jack Jr" parentid=1>Jack III</record>
>
> <record id=7 parent="William" parentid=4>William Jr.</record>
>
> <record id=9 parent="William Jr" parentid=7>William III</record>
>
> <record id=11 parent="William III" parentid=9>William IV</record>
>
>
>
> How do I get.
>
>
>
> Jack, 0
>
>             Jack Jr., 1
>
>                         Jack III, 3
>
>             William, 4
>
>                         William Jr., 7
>
>                                     William III, 9
>
>                                                 William IV, 11
>
>
>
> Special problems.
>
> The number of generations can be infinite.
> Please note I don't have a Jack record, but I need to display Jack. (Logical
> root Record)
> Please note some parent records can be physical records too.

I'm not sure your output is correct there - shouldn't William and Jack
III have the same parent?

Making that assumption, this stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>

<xsl:key name="records-by-parent-id" match="record" use="@parentid"/>

<xsl:template match="/">
       <node>
               <name>Jack, 0</name>
               <xsl:apply-templates select="key('records-by-parent-id', '0')"/>
       </node>
</xsl:template>

<xsl:template match="record">
       <node>
               <name><xsl:value-of select="concat(., ', ', @id)"/></name>
               <xsl:apply-templates select="key('records-by-parent-id', @id)"/>
       </node>
</xsl:template>
</xsl:stylesheet>

Applied to this XML:

<root>
       <record id="1" parent="Jack" parentid="0">Jack Jr</record>
       <record id="4" parent="Jack" parentid="1">William</record>
       <record id="3" parent="Jack Jr" parentid="1">Jack III</record>
       <record id="7" parent="William" parentid="4">William Jr.</record>
       <record id="9" parent="William Jr" parentid="7">William III</record>
       <record id="11" parent="William III" parentid="9">William IV</record>
</root>

Gives this result:

<node>
  <name>Jack, 0</name>
  <node>
     <name>Jack Jr, 1</name>
     <node>
        <name>William, 4</name>
        <node>
           <name>William Jr., 7</name>
           <node>
              <name>William III, 9</name>
              <node>
                 <name>William IV, 11</name>
              </node>
           </node>
        </node>
     </node>
     <node>
        <name>Jack III, 3</name>
     </node>
  </node>
</node>

cheers
andrew

--~------------------------------------------------------------------
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@l... >
--~--

 


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.