Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Max Mumford 266 posts 293 karma points
    Mar 03, 2011 @ 12:01
    Max Mumford
    0

    XSLT Menu not working with new schema

    Hi all,

    We are making our site compatible with the new XSLT schema and our menu is one of the things on the list. Currently it is not looping through the correct pages. If I make a new XSLT file with the "list all sub pages" template and use the "select" statement from that in my old xslt file it still does not work. Can somebody take a quick look through the code below to see if they can spot where it is going wrong?

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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"
      exclude-result-prefixes="msxml umbraco.library">


    <xsl:output method="xml" omit-xml-declaration="yes" />

    <xsl:param name="currentPage"/>

    <xsl:variable name="level" select="1"/>

    <xsl:template match="/">

    <div class="navtree">
    <table cellspacing="0"><tr><td id="navleft"></td>
    <td id="navcentre">
    <ul><li>
      <xsl:if test="$currentPage/@nodeName = 'Home'">
        <xsl:attribute name="class">current</xsl:attribute>
      </xsl:if>

    <href="/">Home</a></li></ul>
    <xsl:call-template name="printListe">
      <xsl:with-param name="node" select="$currentPage/ancestor-or-self::node [@level = 1]"/>  
      <xsl:with-param name="id" select="string('treemenu1')"/>  
    </xsl:call-template>
    </td>
    <td id="navright"></td>
    </tr></table>
    </div>
    </xsl:template>

    <xsl:template name="printListe">
      <xsl:param name="node"/>
      <xsl:param name="id"/>

    <xsl:if test="$node/node [string(./data [@alias='umbracoNaviHide']) != '1' and string(../../../@nodeName) != 'Blog']">
    <ul>
      <xsl:if test="$id != ''">
        <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
      </xsl:if>
      <xsl:for-each select="$node/node [string(./data [@alias='umbracoNaviHide']) != '1']">
        <xsl:sort select="@sortOrder" order="ascending" data-type="number" /><!-- sort nodes -->
        <li>
        <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"><!-- if current node, add "current" class to li -->
          <xsl:attribute name="class">current</xsl:attribute>
        </xsl:if>

        <!-- write link -->
        <href="{umbraco.library:NiceUrl(@id)}">
          <xsl:choose>
              <xsl:when test="string-length(@nodeName) &gt; 25">
            <xsl:attribute name="title"><xsl:value-of select="@nodeName"/></xsl:attribute>
                  <xsl:value-of select="substring(@nodeName,0,24)"/>...
              </xsl:when>
              <xsl:otherwise>
                   <xsl:value-of select="@nodeName"/>
              </xsl:otherwise>
          </xsl:choose>
        </a>
        <xsl:if test="count(./node) &gt; 0"><!-- if node has children -->
          <xsl:call-template name="printListe"><!-- call template again to loop through children and write links -->
            <xsl:with-param name="node" select="."/>
          </xsl:call-template>
        </xsl:if>
        </li>
      </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

     

    I'v tried doing it myself manually but I cannot get it to work.

    Thanks.

    Max.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 03, 2011 @ 12:24
    Dirk De Grave
    0

    you're still using the old schema selectors, need to update those to reflect the new schema.

     

    For example:

    <xsl:for-each select="$node/node [string(./data [@alias='umbracoNaviHide']) != '1']">

    should be rewritten to:

    <xsl:for-each select="$node/* [@isDoc and umbracoNaviHide != '1']">

    I know there are some tools that will help you converting from the old to new schema, just can't find atm. Google for online xslt converter umbraco and you'll find some links (Ah, here's one already: http://blackpoint.dk/umbraco-workbench/tools/convert-xml-schema-to-45-.aspx?p=2)

     

    Hope this helps.

    Cheers,

    /Dirk

     

     



  • Max Mumford 266 posts 293 karma points
    Mar 03, 2011 @ 12:41
    Max Mumford
    0

    Thanks Dirk, I had ran the XSLT updator package which reported no "un-editted" errors and copied over the new XSLT so assumed it was all updated so it must be a problem with the package.

    I have now ran my new script in the link you gave me and it made some improvements. A couple of errors which were not hard to fix and now it is at least showing the pages, just some of the wrong ones :P I will take a look through and see if I can fix the problem and if I can't I'll post again here.

    Thanks for your help,

    Max.

Please Sign in or register to post replies

Write your reply to:

Draft