Developer forum

Forum » Templates » Problem with xslt menu

Problem with xslt menu


Reply

Hello everybody!

 

I am working with at xslt leftmenu!

 

This is what I have inserted in my page template:

 

<!--@If Defined(LeftMenu)--> 
    <div id="leftmenu">
        <div id="navigation">
        <div class="nav_header">

            <span><!--@DwTopPageName--></span>

        </div>
        <!--@LeftMenu-->
        <div class="nav_spacer"></div>
       </div>
    </div>

<!--@EndIf(LeftMenu)-->

 

It workes fine on pages with submenus, but when I have a page with no submenus, it doens't hide, and this is the output i get:

 

<div id="leftmenu">
    <div id="navigation">
    <div class="nav_header"><span>Menu</span></div>             <ul />
<div class="nav_spacer"></div>
 </div> </div>

I don't know why and where the <ul /> comes from?!

Can anybody help me with this problem??

Thanks

 

 


Replies

 
Nicolai Høeg Pedersen
Reply

That  <ul /> comes from your xslt. And since if defined looks for an empty string, and navigation xslt returns something - it will be displayed.

 

So find the error in your xslt and make sure it returns nothing at all if it get no nodes.

 
Reply
np wrote:

That  <ul /> comes from your xslt. And since if defined looks for an empty string, and navigation xslt returns something - it will be displayed.

 

So find the error in your xslt and make sure it returns nothing at all if it get no nodes.

 

I also thought that, but I have now testet the xslt file on our own solution with success.

 

I know that the new solution not has been updated to the newest version. Can that have something to do with it?

 
Nicolai Høeg Pedersen
Reply

Just checked the xml/xslt parsing. Changes has not been done there.

 

XML output could have changed a little. Could you provide the xml documents for both solutions with not sub items? (Use SaveXML=true to save xml document to /Files/Templates/Navigation)

 
Reply
np wrote:

Just checked the xml/xslt parsing. Changes has not been done there.

 

XML output could have changed a little. Could you provide the xml documents for both solutions with not sub items? (Use SaveXML=true to save xml document to /Files/Templates/Navigation)

I have isolated the object which is outputtet even when there is no subitems. It is the first <ul> marked with green.

 

Does it make any sense for you?

 <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />
  <xsl:param name="html-content-type" />
  <xsl:template match="/NavigationTree">
   
    <ul>
      <xsl:apply-templates select="Page">
        <xsl:with-param name="depth" select="1"/>
      </xsl:apply-templates>
    </ul>

  </xsl:template>
 
Nicolai Høeg Pedersen
Reply

One of the attached xml files contains navigation items - thats a difference.

But in your xslt add an if on the count of pages nodes meeting your criterias. If there are no nodes, return nothing.

 
Reply

Hi Guys

Sorry for hi-jacking this thread ...

 

In you XSLT your first template matches /NavigationTree and if that exists it generates the UL tag no matter if the XML contains any Page nodes or not.

 

So what you need to do is to match /NavigationTree[Page] instead.

 

This will look for a NavigationTree node with Page children. And then it will only generate the UL when the XML contains Page nodes.

 

// Sebastian

 
Reply
Dammark wrote:

Hi Guys

Sorry for hi-jacking this thread ...

 

In you XSLT your first template matches /NavigationTree and if that exists it generates the UL tag no matter if the XML contains any Page nodes or not.

 

So what you need to do is to match /NavigationTree[Page] instead.

 

This will look for a NavigationTree node with Page children. And then it will only generate the UL when the XML contains Page nodes.

 

// Sebastian

Amazing!! That did it! Thank you very much Sebastian! Also thank you Nicolai for you effort!

 

Maybe I should begin reading the xml/xslt book I have ordered long time ago :)

 

Have a nice weekend both of you... you just saved mine!

 
Nicolai Høeg Pedersen
Reply

OK Dammark - I get a hint. I'll stay away from this category...

 

You must be logged in to post in the forum