1
votes

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::*"?

1
Can you post the XML you're trying to transform - John
XML markup is posted. Hope it'll help. - Kamilius
I was thinking more of the raw XML your source sends to the XSL file rather than the XSL itself. In the sample you've given though, you might find xsl:choose a better option than xsl:if - see w3schools.com/xsl/xsl_choose.asp - John
I know XSLT, I don't know Umbraco at all. Wtiting XSL without any real idea of what the XML source looks like is something I'd have thought was almost impossible, but I;ve had a look at the Umbraco documentation and they seem to be suggesting you do precisely that. I've edited your question to show a much simpler way of doing your list item, sorry I can't offer an answer - John
Thanks for that comment, it helped with simplyfying a markup a bit. - Kamilius

1 Answers

4
votes

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).