Here is a template I call to generate a menu, and it kinda breaks. Using Xalan, I get heap size error, so my guess would be that something in it is horribly broken and unholy.
I preset the template for the current portion of the website tree, feeding it the path from the root of the site, the language, the current depht (p-i), and a filter. >
What this is supposed to do is to select everything on the current level, and then carry on with the next iteration which should be as simple as updating the "nextLevel" when called again, for the next level of menu...
Help?
Edit: As far as I know, it works as long as I don't go into recursion. I get the first level specified by my depht parameter, and nothing more.
The site is organized like this:
<?xml version="1.0"?>
<site xsi:noNamespaceSchemaLocation="onepagev2.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<page pagename="Alpha">
<language langname="en" path="./en/Alpha" dephtCount="3">
<title>Alpha Anglo</title>
<content>Oh noes.</content>
</language>
<language langname="fr" path="./fr/Alpha" dephtCount="3">
<title>Alpha Franco</title>
<content>Oh non.</content>
</language>
</page>
<page pagename="Beta">
<language langname="en" path="./en/Beta" dephtCount="3">
<title>Beta Anglo</title>
<content>Content B is content B is content B!</content>
</language>
<language langname="fr" path="./fr/Beta" dephtCount="3">
<title>Beta Franco</title>
<content>Contenu B est contenu B est contenu B!</content>
</language>
</page>
<page pagename="Beta2">
<language langname="en" path="./en/Beta/Beta2" dephtCount="4">
<title>Beta Anglo</title>
<content>Content B is content B is content B!</content>
</language>
<language langname="fr" path="./fr/Beta/Beta2" dephtCount="4">
<title>Beta Franco</title>
<content>Contenu B est contenu B est contenu B!</content>
</language>
</page>
</site>
The template:
<xsl:template name="menubuildr">
<xsl:param name="p-path"/>
<xsl:param name="p-lang"/>
<xsl:param name="p-i" select="2"/>
<xsl:param name="p-filter"/>
<xsl:param name="p-max"/>
<xsl:if test="$p-i < $p-max">
<ul>
<xsl:variable name="nextLevel">
<xsl:for-each select="str:split(string($p-path),'/')">
<xsl:if test="position()<$p-i + 1">
<xsl:value-of select="."/>
<xsl:if test="position()<($p-i)">
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:for-each
select="/site/page/language[
starts-with(@path,$p-filter)
and @dephtCount = ($p-i)
and $p-lang = @langname]">
<li>
<xsl:value-of select="@path"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="@dephtCount"/>
<xsl:call-template name="menubuildr">
<xsl:with-param name="p-lang" select="$p-lang" />
<xsl:with-param name="p-filter" select="$nextLevel"/>
<xsl:with-param name="p-i" select="$p-i + 1"/>
<xsl:with-param name="p-path" select="$p-path"/>
<xsl:with-param name="p-max" select="$p-max"/>
</xsl:call-template>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
Sample call:
<div class="menu">Menu
<xsl:call-template name="menubuildr">
<xsl:with-param name="p-lang" select="@langname" />
<xsl:with-param name="p-filter">
<xsl:text>./</xsl:text>
<xsl:value-of select="@langname"/>
</xsl:with-param>
<xsl:with-param name="p-i" select="2"/>
<xsl:with-param name="p-path" select="@chemin"/>
<xsl:with-param name="p-max" select="count(str:split(string(@chemin),'/'))"/>
</xsl:call-template>
<hr/>
</div>