Re: [xsl] simple recursion

Subject: Re: [xsl] simple recursion
From: Jurn Ho <jurn@xxxxxxxxxxxxxxxx>
Date: Tue, 24 Aug 2004 14:32:57 +1000
Hi Jan,

The problem is the bit where you've got <xsl:for-each select="Document">
inside the for-each loop the current node is the Document you've selected, and when you go <xsl:apply-templates/> without any select attribute, it applies templates to children of the Document you've already selected. so in effect you haven't properly processed the Document you selected.


what you can do is tell it to apply-templates with the current document by going <xsl:apply-templates select="."/>

or you can change your for-each loop to an apply-template where you select "Document"s.

hope I make sense :)

cya,
Jurn

At 12:01 PM 24/08/2004, Jan Limpens wrote:
hi,

I am quite beginner when it comes to XML and related technologies, and
I hope someone will give me an explaination on how to solve the
following problem.

I use an XML file to organize a website:

<?xml version="1.0" encoding="utf-8" ?>
<Site Title="My Site">
<Document MIMEType="text/html" Filename="Default.aspx"
Title="Homepage" Description="This is where it all began">
<Document MIMEType="text/html" Filename="Subpage.aspx"
Title="Subpage" Description="This is where it continued">
<Document MIMEType="text/html" Filename="SubSubpage.aspx"
Title="SubSubpage" Description="Now there is so much more" />
<Document MIMEType="text/html" Filename="SubSubpage2.aspx"
Title="SubSubpage2" Description="Now there is so much more,too">
<Document MIMEType="text/html" Filename="SubSubSubpage.aspx"
Title="SubSubpage2" Description="Now there is so much more,too" />
</Document>
<Document MIMEType="image/jpeg" Filename="Beautiful.jpeg" Title="A
beautiful Picture" Description="It shows pure beauty" />
</Document>
<Document MIMEType="text/html" Filename="Subpage2.aspx"
Title="Subpage2" Description="This is where it continued" />
<Document MIMEType="text/html" Filename="AnotherPage.htm"
Title="Another Page" Description="" />
</Document>
</Site>


then I use this xsl stylesheet to convert it to html

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
<html>
<body>
<ol>
<xsl:apply-templates />
</ol>
</body>
</html>
</xsl:template>
<xsl:template match="Document">
<li>
<a href="{@Filename}" title="{@Description}">
<xsl:value-of select="@Title" />
</a>
<xsl:if test="node()">
<ol>
<xsl:for-each select="Document">
<xsl:apply-templates />
</xsl:for-each>
</ol>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>


Somehow the recursion stops somewhere unexpected (for me). It shows like:

   * <Default.htm>Homepage
       * <SubSubpage.htm>SubSubpage
       * <SubSubpage2.htm>SubSubpage2
       * <Beautiful.htm>A beautiful Picture

So obviously it does not actually recurse, it seems, whenever it
enters a deeper level, the parent's following silblings are left out.
But I can not find why this is so. Help?

--
Jan Limpens
http://www.limpens.com

Current Thread