[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: Michael Olszynski <m.olszynski@xxxxxxxxxxxxx>
Date: Wed, 05 Nov 2003 14:38:05 +0100
find parents
Hi Jeni

you are so great, I love you!!!! You´re right. Another template made the "wrong" recursion. Now everything is working fine.

One more question. Is it possible to find out in which level of topic I am?
The thing is, that I have 4 levels, The 4th level has to get another hyperlink, because the 4th level is not a single page, it is the whole accumulation of the 5th level topics is in one page, with html ancers.


position()=last() doesn´t work, because, if I only have 2 topics in each other, the last topic element is not an element of the 4th level. So how can I find out that I´m in level 4 of the nested topic elements.

Thank you

Take care Michael

Jeni Tennison wrote:

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/




-- Michael Olszynski Dipl.-Ing.(FH) Software Engineer

___ |X__________________________________________________________
  X|

eXXcellent solutions gmbh
In der Wanne 55

D-89075 ulm

e | m.olszynski@xxxxxxxxxxxxx
t | +49 [0]731-55026-39
f | +49 [0]731-55026-99
i | www.exxcellent.de
________________________________________________________________

Geschäftsführer: Dr. Martina Maier, Wilhelm Zorn, Gerhard Gruber
Sitz der Gesellschaft: Ulm, Registergericht: Ulm HRB 4309





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.