Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tried (with my very limited knowledge about Umbraco) to clean up your code a bit and remove the redundancy. It looks as though it would work with the XML sample you provided, but I cannot really test it against Umbraco. </p> <pre><code>&lt;!DOCTYPE xsl:stylesheet [ &lt;!ENTITY nbsp "&amp;#x00A0;"&gt; ]&gt; &lt;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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:urlLib="urn:urlLib" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib urlLib "&gt; &lt;xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8" /&gt; &lt;xsl:param name="currentPage" /&gt; &lt;xsl:template match="/"&gt; &lt;div id="kb-categories"&gt; &lt;h3&gt;Categories&lt;/h3&gt; &lt;xsl:apply-templates mode="list" select="/root/node[@nodeTypeAlias='kbHomepage']" /&gt; &lt;/div&gt; &lt;/xsl:template&gt; &lt;!-- matches anything with &lt;node&gt; children and creates an &lt;ul&gt; --&gt; &lt;xsl:template match="*[node]" mode="list"&gt; &lt;!-- prepare a list of all visible children --&gt; &lt;xsl:variable name="visibleChidren" select="node[ data[@alias='showInMenu'] = 1 and ( not(umbraco.library:IsProtected(@id, @path)) or umbraco.library:IsLoggedOn() ) ]" /&gt; &lt;!-- prepare a CSS class for the "selected path" --&gt; &lt;xsl:variable name="display"&gt; &lt;xsl:if test=".//node[generate-id() = generate-id($currentPage)]"&gt; &lt;xsl:text&gt;visible&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;/xsl:variable&gt; &lt;xsl:if test="$visibleChidren"&gt; &lt;ul class="menu kb-menuLevel{$visibleChidren[1]/@level} {$display}"&gt; &lt;xsl:apply-templates mode="item" select="$visibleChidren" /&gt; &lt;/ul&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;!-- matches &lt;node&gt; elements and turns them into list items --&gt; &lt;xsl:template match="node" mode="item"&gt; &lt;li&gt; &lt;xsl:if test="generate-id() = generate-id($currentPage)"&gt; &lt;xsl:attribute name="class"&gt;selected&lt;/xsl:attribute&gt; &lt;/xsl:if&gt; &lt;a href="/kb{{umbraco.library:NiceUrl(@id)}}"&gt; &lt;xsl:value-of select="@nodeName" /&gt; &lt;/a&gt; &lt;!-- if there are any child nodes, render them --&gt; &lt;xsl:if test="node"&gt; &lt;xsl:apply-templates mode="list" select="." /&gt; &lt;/xsl:if&gt; &lt;/li&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Gives you the following. Note that I have escaped the attribute value template in <code>&lt;a href...</code> - remove the double curlies above to enable them again:</p> <pre><code>&lt;div id="kb-categories"&gt; &lt;h3&gt;Categories&lt;/h3&gt; &lt;ul class="menu kb-menuLevel2 visible"&gt; &lt;li&gt; &lt;a href="/kb{umbraco.library:NiceUrl(@id)}"&gt;Menu Item 1&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="/kb{umbraco.library:NiceUrl(@id)}"&gt;Menu Item 2&lt;/a&gt; &lt;ul class="menu kb-menuLevel3 visible"&gt; &lt;li class="selected"&gt; &lt;a href="/kb{umbraco.library:NiceUrl(@id)}"&gt;Menu Item 2.1&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="/kb{umbraco.library:NiceUrl(@id)}"&gt;Menu Item 2.2&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="/kb{umbraco.library:NiceUrl(@id)}"&gt;Menu Item 3&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="/kb{umbraco.library:NiceUrl(@id)}"&gt;Menu Item 4&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Now you could do in CSS:</p> <pre><code>ul.menu { display: hidden; } ul.menu.visible { display: block; } ul.menu li.selected { font-weight: bold; } </code></pre> <p>Does that help you? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload