Jeg skal have lavet en tree menu som kan foldes ud og ind, der er klaret vha. noget js, men ikke nok med at den 'huske' at folde sig rigtig ud selv om man går til en underside...
Jeg er ikke selv særlig god til xslt, så koden her under skal sikker omstruktureres en del, men det stor problem er at at overskrive en variabels værdi i dette tilfælde 'forceDisplay'.
Er der nogle som kan fortælle mig hvordan jeg overskriver en variable og evt. laver strukturen af denne her menu lidt bedre?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="forceDisplay"/>
<xsl:variable name="maxLevelForSitemap" select="2"/>
<xsl:template match="/">
<div id="sitemap">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById(1045)/ancestor-or-self::node [@level=1]"/>
</xsl:call-template>
</div>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1']">
<xsl:variable name="forceDisplay" select="0"></xsl:variable>
<xsl:value-of select="$forceDisplay" />
<xsl:call-template name="shouldDisplay">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
<xsl:value-of select="$forceDisplay" />
<!-- Skjul noder -->
<xsl:if test="current()/@level > current()/@level">
<table border="0" cellpadding="1" cellspacing="1" style="display:none">
<tr>
<td><img src="/images/text.gif" alt="" /></td>
<td><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a>
</td>
</tr>
</table>
</xsl:if>
<xsl:choose>
<xsl:when test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1']) = 0">
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td><img src="/images/text.gif" alt="" /></td>
<td><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td><a href="javascript:Toggle('{@id}');"><img src="/images/folder.gif" alt="" /></a></td>
<td><a href="#"><xsl:value-of select="@nodeName" /></a></td>
</tr>
</table>
<xsl:choose>
<xsl:when test="$forceDisplay = 1">
<div id="{@id}" style="margin-left:20px;">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</div>
</xsl:when>
<xsl:otherwise>
<div id="{@id}" style="display:none; margin-left:20px;">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="shouldDisplay">
<xsl:param name="parent"/>
<xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1']">
<xsl:choose>
<xsl:when test="$currentPage/@id=@id">
We are in!!!
<xsl:variable name="forceDisplay" select="1"></xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="shouldDisplay">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
// RTK