Reputation: 587
My Umbraco project has following structure:
Content
-Home
--Contacts
--Offices
-About
Home has '/' address, and is an Index page. Can somebody tell me how to get Both - Home and About elements to put them into menu, through XSLT? Currently i can take only subnodes by level of current page, which is Home, so i get only Contacts and Offices. I can't take'em by documentType, because i want a dynamic, and not a hardcoded one. Is there a way to get Home and About constantly for display in menu? I'm completly new to XSLT, and second day in Umbraco itself.
Edit: Here is a part of XML, under
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>
<xsl:template match="/">
<!-- The fun starts here -->
<ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:if test="$currentPage/@id = @id">
<li class="selected">
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:if>
<xsl:if test="$currentPage/@id != @id">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:if>
<xsl:value-of select="$currentPage/id"/>
</xsl:for-each>
</ul>
</xsl:template>
Edit2: By taking off level equality, i've got "self", which is "Home", but still no "About". Maybe you know how to find info about "X-Path" selector such as "ancestor-or-self::*"?
Upvotes: 1
Views: 546
Reputation: 587
I've finaly found an answer. The way to access all elements through a project root element is using of "$currentPage/ancestor::root//*". That's how my markup looks now, with a help of John, in simplyfying 'if' statement.
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>
<xsl:template match="/">
<!-- The fun starts here -->
<ul>
<xsl:for-each select="$currentPage/ancestor::root//* [@level = $level and name() != 'Home' and @isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:if test="$currentPage/@id = @id">
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
<xsl:value-of select="$currentPage/id"/>
</xsl:for-each>
</ul>
On the exit i'm getting all elements of "content" except "Home" (i just don't simply need it in my menu).
Upvotes: 4