Developer forum

Forum » Templates » .xslt menu help

.xslt menu help


Reply

I have a menu item in level 2 called "Kategori". I want to show all level 3 menu items under "kategori".

I’m a bit green when it comes to xslt. I only managed to get it to show all level 3 items in general.


This is my code:

 <ul id="M0">
<xsl:apply-templates select="Page">
<xsl:with-param name="depth" select="1"/>
xsl:apply-templates>
ul>

xsl:template>

<xsl:template match="Page">
<xsl:param name="depth"/>

<li>
<a>
<xsl:if test="@Allowclick='True'">
<xsl:if test="@AbsoluteLevel='3'">
<xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/>xsl:attribute>
xsl:if>
xsl:if>
<xsl:if test="@Active='True'">
<xsl:attribute name="id">activeitemxsl:attribute>
xsl:if>
<xsl:value-of select="@MenuText" disable-output-escaping="yes"/>
a>
<xsl:if test="@InPath='True'">
<xsl:if test= 0"" ispart="true" dirty="false">"count(Page) > 0">
<ul class="M{@AbsoluteLevel}">
<xsl:apply-templates select="Page">
<xsl:with-param name="depth" select="$depth+1"/>
xsl:apply-templates>
ul>
xsl:if>
xsl:if>
li>
xsl:template>
xsl:stylesheet>



This is my XML file:

http://kartell.net.dynamicweb-cms.com/Admin/Public/GetNavigationXML.aspx


Replies

 
Yury Zhukovskiy
Reply

Hi, you need to do:

1.      Set “expand all” fold out for your menu.

2.      Chage xslt, by default “LIClean.xslt”, like in below example

Instead of count(Page) you need to use:

<xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))">

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

 

  <!--

  Description: ul/li based navigation. No features from admin implemented.

  Recommended settings:

  Fold out: True or False

  Upper menu: Dynamic or Static

  First level: > 0

  Last level: >= First level

  -->

 

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />

  <xsl:param name="html-content-type" />

  <xsl:template match="/NavigationTree">

   

    <xsl:if test="count(//Page) &gt; 0">

      <ul>

        <xsl:apply-templates select="Page">

          <xsl:with-param name="depth" select="1"/>

        </xsl:apply-templates>

      </ul>

    </xsl:if>

 

  </xsl:template>

 

  <xsl:template match="//Page">

    <xsl:param name="depth"/>

    <li>    

      <a>

        <xsl:if test="@InPath='True'">

          <xsl:attribute name="class">inpath</xsl:attribute>

        </xsl:if>

        <xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>       

        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>

      </a>

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))">

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

    </li>

  </xsl:template>

 

</xsl:stylesheet>

 

Kind Regards

Zhukovskiy Yury

 
Dennis Thrane
Reply
Hi Yury,

Can I get it not to output my level 2 navigation - only level 3?
Or will I have to hide level 2 with CSS?

http://www.kartellshop-hellerup.dk/Kartell-online.aspx?Purge=True

Best Regards
Dennis
 
Yury Zhukovskiy
Reply
Hi Dennis

I have modified above example and separete templates for a page by using mode attribute, see bolow.

Now it renders subpages of “Kategori” page and their subpages and ignore “Kategori” and “Designer” pages.

I have crated a file “siteLayoutLeftNav_Kartell_TEST_yzh.xsl” in your “/Templates/Navigation” folder, you can use it as example.

 

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

 

  <!--

  Description: ul/li based navigation. No features from admin implemented.

  Recommended settings:

  Fold out: True or False

  Upper menu: Dynamic or Static

  First level: > 0

  Last level: >= First level

  -->

 

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />

  <xsl:param name="html-content-type" />

  <xsl:template match="/NavigationTree">

   

    <xsl:if test="count(//Page) > 0">     

        <xsl:apply-templates select="Page" mode="Root">

          <xsl:with-param name="depth" select="1"/>

        </xsl:apply-templates>

    </xsl:if>

 

  </xsl:template>

 

  <xsl:template match="//Page" mode="Root" >

    <xsl:param name="depth"/>   

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))"> 

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="Child">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

  </xsl:template>

 

 

    <xsl:template match="//Page" mode="Child" >

    <xsl:param name="depth"/>

    <li>

      <a>

        <xsl:attribute name="class">

        <xsl:if test="@InPath='True'">inpath </xsl:if>

        <xsl:if test="position() = 1">firstitem </xsl:if>

        <xsl:if test="position() = count(//Page)">lastitem </xsl:if>

        <xsl:if test="@Active='True'">activeitem</xsl:if>

</xsl:attribute>

        <xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>

        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>

      </a>

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))"> 

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="Child">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

    </li>

  </xsl:template>

 

</xsl:stylesheet>

 

 

Kind Regards 

Zhukovskiy Yury



 
Dennis Thrane
Reply

Hi Zhukovskiy Yury,
 

It's neraly working now. Only one little thing, hov do i get it to also show menu levels under fx "Kategori" --> "Stole".
Right now I will only show first level under "Kategori".  

 
Yury Zhukovskiy
Reply

Hi Dennis.

Sorry for a long response.

You need to change condition in your xslt file (siteLayoutLeftNav_Kartell_TEST.xsl)

In the place where you check menu text equals “Kategori” you need to add checking for “Stole” name in mode “Child” template match.

Final condition will look like this:

 

<xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori') or (@AbsoluteLevel = 3 and @MenuText='Stole'))"> 

 

Final XSLT will look like this

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

 

  <!--

  Description: ul/li based navigation. No features from admin implemented.

  Recommended settings:

  Fold out: True or False

  Upper menu: Dynamic or Static

  First level: > 0

  Last level: >= First level

  -->

 

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />

  <xsl:param name="html-content-type" />

  <xsl:template match="/NavigationTree">

   

    <xsl:if test="count(//Page) > 0">     

        <xsl:apply-templates select="Page" mode="Root">

          <xsl:with-param name="depth" select="1"/>

        </xsl:apply-templates>

    </xsl:if> 

  </xsl:template>

 

  <xsl:template match="//Page" mode="Root" >

    <xsl:param name="depth"/>   

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))"> 

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="Child">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

  </xsl:template>

 

 

    <xsl:template match="//Page" mode="Child" >

    <xsl:param name="depth"/>

    <li>

      <a>

        <xsl:attribute name="class">

        <xsl:if test="@InPath='True'">inpath </xsl:if>

        <xsl:if test="position() = 1">firstitem </xsl:if>

        <xsl:if test="position() = count(//Page)">lastitem </xsl:if>

        <xsl:if test="@Active='True'">activeitem</xsl:if>

</xsl:attribute>

        <xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>

        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>

      </a>

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori') or (@AbsoluteLevel = 3 and @MenuText='Stole'))"> 

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="Child">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

    </li>

  </xsl:template>

</xsl:stylesheet>

 

 

 

Kind Regards

 

Zhukovskiy Yury


 
Dennis Thrane
Reply

Hi Yury,
 

It only has to show the menu items under "Stole" when i click "Stole". And it has to show menu items under "Borde" when i click "Borde" etc. I dont want it to show all menu items under "Stole" as default.
 

I just want the next menu level also to work.

 
Yury Zhukovskiy
Reply
I.e. You want to expand all sub children of second level. Confirm please
 
Yury Zhukovskiy
Reply
Try this one.
I have added ChildExpandAll mode. It should expand all subnodes.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

 

  <!--

  Description: ul/li based navigation. No features from admin implemented.

  Recommended settings:

  Fold out: True or False

  Upper menu: Dynamic or Static

  First level: > 0

  Last level: >= First level

  -->

 

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />

  <xsl:param name="html-content-type" />

  <xsl:template match="/NavigationTree">

   

    <xsl:if test="count(//Page) > 0">     

        <xsl:apply-templates select="Page" mode="Root">

          <xsl:with-param name="depth" select="1"/>

        </xsl:apply-templates>

    </xsl:if> 

  </xsl:template>

 

  <xsl:template match="//Page" mode="Root" >

    <xsl:param name="depth"/>   

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))"> 

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="Child">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

  </xsl:template>

 

 

    <xsl:template match="//Page" mode="Child" >

    <xsl:param name="depth"/>

    <li>

      <a>

        <xsl:attribute name="class">

        <xsl:if test="@InPath='True'">inpath </xsl:if>

        <xsl:if test="position() = 1">firstitem </xsl:if>

        <xsl:if test="position() = count(//Page)">lastitem </xsl:if>

        <xsl:if test="@Active='True'">activeitem</xsl:if>

</xsl:attribute>

        <xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>

        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>

      </a>

        <xsl:if test="count(Page) and (@AbsoluteLevel &lt; 2 or (@AbsoluteLevel = 2 and @MenuText='Kategori'))"> 

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="ChildExpandAll">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

        </xsl:if>

    </li>

  </xsl:template>

 

    <xsl:template match="//Page" mode="ChildExpandAll" >

    <xsl:param name="depth"/>

    <li>

      <a>

        <xsl:attribute name="class">

        <xsl:if test="@InPath='True'">inpath </xsl:if>

        <xsl:if test="position() = 1">firstitem </xsl:if>

        <xsl:if test="position() = count(//Page)">lastitem </xsl:if>

        <xsl:if test="@Active='True'">activeitem</xsl:if>

</xsl:attribute>

        <xsl:attribute name="href"><xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/></xsl:attribute>

        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>

      </a>

          <ul class="M{@AbsoluteLevel}">

            <xsl:apply-templates select="Page" mode="ChildExpandAll">

              <xsl:with-param name="depth" select="$depth+1"/>

            </xsl:apply-templates>

          </ul>

    </li>

  </xsl:template>

 

</xsl:stylesheet>

 

 

Zhukovskiy Yury

 


 
Dennis Thrane
Reply

Hi Youry,


Yes, expand all sub children of second level. The script did not work, it does not expand the second level


Menu text "Kategori" is menu leven 2.

Menu text "Stole" is menu leven 3.
Then I need it to show sub children to "stole" when i click it etc.
 

 

 

 
Yury Zhukovskiy
Reply
I have modified siteLayoutLeftNav_Kartell_TEST.xsl and made "Stole" expanded by default.
Check please, is it what you want? http://www.kartellshop-hellerup.dk/Kartell-online.aspx

 
Dennis Thrane
Reply
I don't want "stole" to be expanded by default. I should only expand when i click "stole".
 
Nicolai Høeg Pedersen
Reply
Hi Dennis

This forum is meant as a help for you to get on when stock with DW specific things. We cannot do implementations for you - then you need to get hold of a freelancer or an other partner.
You can try html24.dk, blackworks.dk or any partner you can find on www.dynamicweb.dk

 
Lennart Jepsen
Reply
Hi Yuri,

-on behalf of my colleague Dennis-

Your help is much appreciated.
The specific problem has been resolved for now. :)

 
Yury Zhukovskiy
Reply

Perfect.

You're welcome.

 

You must be logged in to post in the forum