Hi,
I'm trying to create navigation menu using XSLT.
In the menu I'd like to always show all the nodes of the first and the second navigation level so I'm using foreach loop.
It works well for the first level but I cannot get access to the second level nodes.
<xsl:template match="/NavigationTree[Page]">
<ul id = "navigation">
<xsl:for-each select="Page">
<li><xsl:value-of select="@MenuText" /></li>
<xsl:value-of select="count(Page)"/>
count(Page) is always = 0 but i think it should return the number of the child nodes.
<xsl:for-each select="child::*">
- the loop does not execute since i have
no access to the child nodes.
</xsl:for-each>
</xsl:for-each>
</ul>
GetNavigationXML.aspx:
<Page ID="1" />
<Page ID="2" >
<Page ID="3" "/>
<Page ID="4"/>
</Page>
<Page ID="5" >
<Page ID="6" />
<Page ID="7" />
</Page>
<Page ID="8" />
I'm sure I'm missing something obvious since I'm new to XSLT.
Thank you for any help.
Piotr Jablonski
Developer forum
E-mail notifications
Creating XSLT menu
Posted on 04/05/2010 10:07:35
Replies
Posted on 04/05/2010 10:23:06
Hi Piotr
Try this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="NavigationTree[Page]" />
</xsl:template>
<xsl:template match="NavigationTree">
<ul>
<xsl:apply-templates select="Page" />
</ul>
</xsl:template>
<xsl:template match="Page">
<li>
<a href="{@Href}">
<xsl:value-of select="@MenuText" />
</a>
<xsl:if test="Page">
<ul>
<xsl:apply-templates select="Page" />
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
// Dammark
Try this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="NavigationTree[Page]" />
</xsl:template>
<xsl:template match="NavigationTree">
<ul>
<xsl:apply-templates select="Page" />
</ul>
</xsl:template>
<xsl:template match="Page">
<li>
<a href="{@Href}">
<xsl:value-of select="@MenuText" />
</a>
<xsl:if test="Page">
<ul>
<xsl:apply-templates select="Page" />
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
// Dammark
Posted on 04/05/2010 10:41:01
Thank you for the answer but still, even using your template, I'm getting only the first level nods.
Posted on 04/05/2010 10:49:07
Can you throw me a link ?
// Dammark
// Dammark
Posted on 04/05/2010 11:04:29
The page is not online yet.. just on my local machine.
I attach a full result of GetNavigationXML file is it what you were thinking of seeing?
I attach a full result of GetNavigationXML file is it what you were thinking of seeing?
Posted on 04/05/2010 11:09:40
Could you rename the aspx file to xml please ?
Posted on 04/05/2010 11:43:49
Hi again
Unzip the attached file and open the xml file in IE.
Then you will see how it should work.
If it doesn't, then there is a bug on your website and you need to register a case in the service desk.
// Dammark
Unzip the attached file and open the xml file in IE.
Then you will see how it should work.
If it doesn't, then there is a bug on your website and you need to register a case in the service desk.
// Dammark
Posted on 04/05/2010 11:57:12
Can you please attach the file ;)
You must be logged in to post in the forum