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

Re: recursive call of template - how to find parents

Subject: Re: recursive call of template - how to find parents
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 5 Nov 2003 13:12:41 +0000
xsl parent recursion
Hi Michael,

> It is that way, because I still used my old sitemap template, which
> you recommended to replace with the sitemap template you wrote. So I
> did replace also the sitemap template. And now, I get a stack
> overflow error, when I try to generate the homepage.

That usually indicates infinite recursion, but I can't see anything in
the code I recommended that would give you infinite recursion. I
tried:

XML document:
<homepage>
  <topic name="point1" filename="asdf">   
    <topic name="subpoint1" filename="asdf1">       
      <topic name="subsubpoint1" filename="asdf2">           
        <topic name="subsubsubpoint1" filename="asdf3" />
      </topic>
    </topic>
    <topic name="subpoint2" filename="asdf4" />
  </topic>
  <topic name="point2" filename="asdf5" />
  <topic name="point3" filename="asdf6" />
  <topic name="point4" filename="asdf7" />
</homepage>

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

<xsl:output indent="yes" />

<xsl:template match="/">
  <xsl:call-template name="sitemap" />
</xsl:template>

<xsl:template name="sitemap">
  <ul>
    <xsl:apply-templates select="homepage/topic" />
  </ul>
</xsl:template>

<xsl:template match="topic">
  <li>
    <a>
      <xsl:attribute name="href">
        <xsl:for-each select="ancestor-or-self::topic">
          <xsl:value-of select="@filename" />
          <xsl:if test="position() != last()">/</xsl:if>
        </xsl:for-each>
      </xsl:attribute>
      <xsl:value-of select="@name"/>
    </a>
    <xsl:if test="topic">
      <ul>
        <xsl:apply-templates select="topic"/>
      </ul>
    </xsl:if>
  </li>
</xsl:template>

</xsl:stylesheet>

and got, as the result:

<ul>
   <li>
      <a href="asdf">point1</a>
      <ul>
         <li>
            <a href="asdf/asdf1">subpoint1</a>
            <ul>
               <li>
                  <a href="asdf/asdf1/asdf2">subsubpoint1</a>
                  <ul>
                     <li>
                        <a href="asdf/asdf1/asdf2/asdf3">subsubsubpoint1</a>
                     </li>
                  </ul>
               </li>
            </ul>
         </li>
         <li>
            <a href="asdf/asdf4">subpoint2</a>
         </li>
      </ul>
   </li>
   <li>
      <a href="asdf5">point2</a>
   </li>
   <li>
      <a href="asdf6">point3</a>
   </li>
   <li>
      <a href="asdf7">point4</a>
   </li>
</ul>

So I guess the problem is somewhere that you haven't shown us.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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