Hello. I seem to be having trouble with an XSLT based menu I'm constructing.
I have a main XSLT which includes another one for the menu. The data for the menu is in it's own XML file. That said, I need to use the document() function in order to transform the menu data and still transform the main data. So far, so good. But for some reason the function isn't working as I though it would.
The important part of the main XSLT:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="navigation.xsl"/>
<xsl:template match="/">
...
<div id="left">
<xsl:call-template name="navigation"/>
</div>
...
</xsl:template>
</xsl:stylesheet>
Where navigation.xsl is
Code:
<?xml version="1.0" encoding="windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="Nav" select="'navigation.xml'"/>
<xsl:template name="navigation">
<xsl:for-each select="document($Nav,/)">
<xsl:call-template name="menu" />
</xsl:for-each>
</xsl:template>
<xsl:template name="menu">
<xsl:for-each select="document($Nav,menu)">[list]
<xsl:for-each select="document($Nav,item)">
<li>
<a href="{document($Nav,link)}">
<xsl:value-of select="document($Nav,menu/item/title)"/>
</a>
</li>
<xsl:if test="document($Nav,menu)">
<xsl:call-template select="menu"/>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
And the problematic XML for which I need the document function.
Code:
<?xml version="1.0" encoding="windows-1251"?>
<menu>
<item>
<title>Home</title>
<link>#</link>
</item>
<item>
<title>Products</title>
<link>#</link>
<menu>
</menu>
</item>
</menu>
The reason I'm having a template navigation to call the second template menu is that menu is suppose to be repeated for every nested menu.
The problem is that for some reason, every document() function below
Code:
<xsl:for-each select="document($Nav,menu)">
is treated as a relative path to the root of the document, not the previously selected by this for-each path (in this case- menu). It gets worse. Because of call-template which selects itself and because the root <menu> would always exist in the whole file, the template is being looped infinetly, thus eventually causing IE to crash. At the same time, FF is being wise enough to not actually select anything below
Code:
<xsl:for-each select="document($Nav,menu)">
My desired output is something like this:
Code:
[list]
<li>
<a href="#>Home</a>
</li>
<li>
<a href="#">Products</title>
[list]
</ul>
</li>
</ul>
Any ideas?