Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] xslt for hierarchical data

From: Jody Robert Ford <jody.r.ford@-----.--->
To: <xml-dev@-----.---.--->
Date: 2/8/2006 1:14:00 AM
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><o:p></o:p>



<span style='font-size:
12.0pt'>And, truthfully, I'm trying to format the display to work like this:

http://www.codeproject.com/jscript/dhtml_treeview.asp

 <o:p></o:p>





<span style='font-size:
12.0pt'>Can anyone help?  I'm a but of a time crunch - as always.<o:p></o:p>





<span style='font-size:
12.0pt'> <o:p></o:p>





<span style='font-size:
12.0pt'>thanks again,<o:p></o:p>





<span style='font-size:
12.0pt'>

-jody <o:p></o:p>



<o:p> </o:p>



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

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

--~--<o:p></o:p>



<span style='font-size:
12.0pt'><o:p> </o:p>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent