The problem I have now is that the li is also shown for the root item which i obviously don't want.
I tried to correct this by putting the <li> tag inside the if that tests the current level. but then I get the error that the <li> doesn't have a closing tag (quite normal of course). so I decided to put the <li>, </li> and the following if that tests for children inside the if that tests the level.
but this doesn't work, which is quite a mystery to me.
So I need a way to add logic around the <li> tag to decide wether or not to show it. which brings me back to the error I get when the closing </li> tag is not in the same if. I tried to show <li> like this <li>and this <![CDATA<li>]]>, which also did not result in the wanted result.
I hope I explained the problem correctly. any help would be greatly apreciated.
@tommy: that was idea too at first, but then it didn't display anything.
@seth: that did the trick. I tried something similar with an if statement but now I see I made a logical mistake. Guess I'm not yet used to using the choose statement instead of the if statement :)
the choose statement works like the classic if... else statement.
you first declare the choose (<xsl:choose>)
then if some condition is true we do that thing
<xsl:when test="isConditionTrue">
<!-- Some things to do -->
</xsl:when>
You can put in as many (<xsl:when test="isConditionTrue" >) as you want.
Then, there is a catch all (<xsl:otherwise> <!-- Do this if nothing else is true --> </xsl:otherwise>), which will run if none of the other when conditional statments are true.
Then, close your choose (</xsl:choose>).
It is a very useful built in tool, which allows you to add a bit more logic to your XSLT.
sitemap nested if problem
I'm stil a newbie at Umbraco and XSLT so please forgive me if this is a dumb question. I'm using the following code in my xslt to create a sitemap:
The problem I have now is that the li is also shown for the root item which i obviously don't want.
I tried to correct this by putting the <li> tag inside the if that tests the current level. but then I get the error that the <li> doesn't have a closing tag (quite normal of course). so I decided to put the <li>, </li> and the following if that tests for children inside the if that tests the level.
like this:
but this doesn't work, which is quite a mystery to me.
So I need a way to add logic around the <li> tag to decide wether or not to show it. which brings me back to the error I get when the closing </li> tag is not in the same if. I tried to show <li> like this <li> and this <![CDATA<li>]]>, which also did not result in the wanted result.
I hope I explained the problem correctly. any help would be greatly apreciated.
Hi Ruben
How about moving your
test to e.g. the for-each selection instead - then you only iterate the nodes below your start level.
>Tommy
I am not exactly sure what you want inside your topLevel and what you don't but you could use a choose statement:
<xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level <= $maxLevelForSitemap]">
<xsl:choose>
<xsl:when test="current()/@level > $startLevel >
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1'
and @level <= $maxLevelForSitemap]) > 0 ">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</li>
</xsl:when>
<xsl:otherwise>
<xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1'
and @level <= $maxLevelForSitemap]) > 0 ">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
@tommy: that was idea too at first, but then it didn't display anything.
@seth: that did the trick. I tried something similar with an if statement but now I see I made a logical mistake. Guess I'm not yet used to using the choose statement instead of the if statement :)
thanks for the help and super fast response guys!
ruben,
the choose statement works like the classic if... else statement.
you first declare the choose (<xsl:choose>)
then if some condition is true we do that thing
<xsl:when test="isConditionTrue">
<!-- Some things to do -->
</xsl:when>
You can put in as many (<xsl:when test="isConditionTrue" >) as you want.
Then, there is a catch all (<xsl:otherwise> <!-- Do this if nothing else is true --> </xsl:otherwise>), which will run if none of the other when conditional statments are true.
Then, close your choose (</xsl:choose>).
It is a very useful built in tool, which allows you to add a bit more logic to your XSLT.
Thanks for the explanation Seth. Guess I should really dive into some xslt and umbraco tutorials :)
is working on a reply...