OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xsl] xslt for hierarchical data

[ Lists Home | Date Index | Thread Index ]
  • To: <xml-dev@lists.xml.org>
  • Subject: RE: [xsl] xslt for hierarchical data
  • From: Jody Robert Ford <jody.r.ford@gmail.com>
  • 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


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@gmail.com> wrote:

On 1/11/06, Jody Robert Ford <jody.r.ford@gmail.com> 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@lists.mulberrytech.com >
--~--

 





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS