Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 December 5th, 2005, 05:51 PM
Registered User
 
Join Date: Dec 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recursive Transform

Hi everyone! I'm new to XSLT so please bear with me. I'm trying to generate nested lists based on the XML below. The ParentID field is a reference to the ID field in other "tables." For example ParentID=0 is the root list, ParentIDs of 1 refer to the root list item with an ID of 1. My problem is generating the child lists specifically the call to the template inside of itself (recursive call). What ever I try in the select attribute (<xsl:with-param name="content" select="/"/>) it does not loop back through the document.

Thanks.

Here are my 2 templates in one XSLT file
Code:
<xsl:template match="NewDataSet">
<div id="product_list">[list] 
<xsl:call-template name="category">
<xsl:with-param name="content" select="NewDataSet"/>
<xsl:with-param name="ParentID" select="0"/>
</xsl:call-template>
</ul>  
</div>
</xsl:template>

<xsl:template name="category">
<xsl:param name="ParentID"/>
<xsl:param name="content"/>
<xsl:for-each select="Table">
<xsl:if test="ParentID=number($ParentID)">
<li>
<a>
<xsl:attribute name="href">/url.aspx?categoryID=<xsl:value-of select="ID" /></xsl:attribute>
<xsl:value-of select="Name" />
</a>
<xsl:call-template name="category">
<xsl:with-param name="content" select="/"/>
<xsl:with-param name="ParentID" select="ID"/>
</xsl:call-template>
</li>
</xsl:if>
</xsl:for-each>
</xsl:template>
Here is my xml document:
Code:
<?xml version="1.0" encoding="utf-8"?>
<NewDataSet>
  <Table>
    <ID>1</ID>
    <Name>Book</Name>
    <Description />
    <ParentID>0</ParentID>
  </Table>
  <Table>
    <ID>3</ID>
    <Name>Food</Name>
    <Description />
    <ParentID>1</ParentID>
  </Table>
  <Table>
    <ID>6</ID>
    <Name>Men's</Name>
    <Description />
    <ParentID>4</ParentID>
  </Table>
  <Table>
    <ID>10</ID>
    <Name>Dresses</Name>
    <Description />
    <ParentID>9</ParentID>
  </Table>
  <Table>
    <ID>12</ID>
    <Name>Jackets</Name>
    <Description />
    <ParentID>6</ParentID>
  </Table>
  <Table>
    <ID>11</ID>
    <Name>Sports Wear</Name>
    <Description />
    <ParentID>9</ParentID>
  </Table>
  <Table>
    <ID>7</ID>
    <Name>Women's</Name>
    <Description />
    <ParentID>4</ParentID>
  </Table>
  <Table>
    <ID>4</ID>
    <Name>Clothes</Name>
    <Description />
    <ParentID>0</ParentID>
  </Table>
  <Table>
    <ID>2</ID>
    <Name>Dating</Name>
    <Description />
    <ParentID>1</ParentID>
  </Table>
  <Table>
    <ID>5</ID>
    <Name>Stuff</Name>
    <Description />
    <ParentID>0</ParentID>
  </Table>
  <Table>
    <ID>8</ID>
    <Name>Boy's</Name>
    <Description />
    <ParentID>4</ParentID>
  </Table>
  <Table>
    <ID>9</ID>
    <Name>Girl's</Name>
    <Description />
    <ParentID>4</ParentID>
  </Table>
</NewDataSet>

Chuck Boyer, MCSD.NET
Dir. of Production and Development
Edge Media, Inc.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive Coding arnabghosh Classic ASP Professional 2 July 9th, 2007 02:06 AM
recursive query cathiec SQL Language 2 August 25th, 2006 05:58 AM
Recursive Function MargateFan XSLT 2 May 4th, 2006 02:52 AM
transform in a loop vs recursive template ramarc XSLT 3 April 10th, 2006 04:40 PM
recursive transform output different in IE and FF seamus7 XSLT 2 January 20th, 2006 06:01 PM





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