Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2005, 07:21 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Handling recursive XML Nodes using XSL

Hi... I have an XML of the form...

<client name="abc">
abc
   <client name="def">
   def
   </client>
   <client name="ghi">
   ghi
      <leaf-client name="jkl">
      jkl
      </leaf-client>
      <leaf-client name="mno">
      mno
      </leaf-client>
   </client>
</client>

I have to generate a hierarchical table of the form
abc
def ghi
       jkl mno

Could somebody provide a hint about how recursive nodes can be handled using XSL?

Thanks


 
Old June 16th, 2005, 07:49 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Recursive nodes are generally handled using xsl:apply-templates.

But I don't think that's your problem here.

Your problem is seriously underspecified: it's impossible to tell from this example what the set of possible inputs is, and how inputs different from the one shown would be transformed.

In your example, a client either has children or has following siblings, it never has both. Will that always be the case?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 20th, 2005, 11:19 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I am afraid that this will always be the case. Each node can have the the same node 'client' or 'leaf-client' as a child. Any suggestions/hints would be greatly appreciated.

Quote:
quote:Originally posted by mhkay
 Recursive nodes are generally handled using xsl:apply-templates.

But I don't think that's your problem here.

Your problem is seriously underspecified: it's impossible to tell from this example what the set of possible inputs is, and how inputs different from the one shown would be transformed.

In your example, a client either has children or has following siblings, it never has both. Will that always be the case?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 21st, 2005, 02:15 AM
Authorized User
 
Join Date: May 2005
Location: bangalore, karnataka, India.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meetnaveen4u
Default

Well i belive u need to see some examples regarding display of xml in treeview fashion using xslt. This might give u an idea on how to go for recursive program.


Thanks &amp; Regards
Naveen.
 
Old June 21st, 2005, 01:21 PM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Thanks Naveen, I will loook that up too.

In the mean time I am posting the XSL I wrote. As can be seen parts are repetitive. Can somebody tell me if this generic parts can be written in a better manner.


<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">

<TR>
  <TH>Parent</TH>
  <TH>Client</TH>
</TR>

<TR>
  <TD>
    ON24
  </TD>

  <TD>
  <TABLE BORDER="1" CELLSPACING="0" CELLPADDING="10">
  <xsl:for-each select="rootclient/client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>

  <TD>
  <TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">
  <xsl:for-each select="client/client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>

  <TD>
  <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="5">
  <xsl:for-each select="client/client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>
  </TR>
  </xsl:for-each>
  <xsl:for-each select="client/leaf-client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>
  </TR>
  </xsl:for-each>
  <xsl:for-each select="leaf-client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>
  </TR>
  </xsl:for-each>
  </TABLE>
  </TD>

  </TR>
  </xsl:for-each>
  <xsl:for-each select="client/leaf-client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>
  </TR>
  </xsl:for-each>
  <xsl:for-each select="leaf-client">
  <TR>
  <TD>
  <xsl:value-of select="@name"/>
  </TD>
  </TR>
  </xsl:for-each>
  </TABLE>
  </TD>

  </TR>
  </xsl:for-each>
  </TABLE>
  </TD>
</TR>

</TABLE>

</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
 
Old June 21st, 2005, 02:45 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">


You really don't want to be using WD-xsl. It's an obsolete Microsoft-proprietary dialect, and it's almost impossible to get any information about it any more, let alone support. Switch to XSLT.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference




Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing nodes as they appear in the XML spidergirl1979 XSLT 4 January 21st, 2008 05:50 AM
Recursive nodes in XML Schema XSLTer XML 1 April 13th, 2007 12:25 PM
Drawing XSL recursive, could it be? flikifliki XSLT 1 September 22nd, 2005 08:23 AM
Using a recursive template for various nodes spencer.clark XSLT 5 August 2nd, 2005 03:49 PM
XSL-help-sum of nodes baed on a condition skumar80 XSLT 2 November 8th, 2003 10:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.