Copied to clipboard

Flag this post as spam?

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


  • TaoistTotty 246 posts 314 karma points
    Jul 30, 2010 @ 12:49
    TaoistTotty
    0

    Error when using apply-templates and getting details from macro

    I am seeing a strange error in both 4.5 and also in 4.5.1.

    The following code caused the XSLT to not save, and the whole site (including published pages) to stop working for about 2 minutes (or what seems like hours).

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;">
                                <!ENTITY hidden "umbracoNaviHide = 1">
                                <!ENTITY node "*[@isDoc]">
    ]>
    <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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

      <xsl:variable name="homeMenu" select="/macro/homeItem"/>
      <xsl:variable name="homePage" select="umbraco.library:GetXmlNodeById($homeMenu)"/>
      <ul>
        <xsl:apply-templates select="$homePage | $homePage/&node;"/>
      </ul>

    </xsl:template>
    <xsl:template match="&node;">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="@id = $currentPage/@id">
            <xsl:attribute name="class">
              selected
            </xsl:attribute>
          </xsl:if>
          <xsl:value-of select="@nodeName"/>
        </a>
      </li>
    </xsl:template>
        <xsl:template match="&node;[&hidden;]"/>    
    </xsl:stylesheet>

    If I change the line:

    <xsl:variable name="homeMenu" select="/macro/homeItem"/>

    To read

    <xsl:variable name="homeMenu" select="1234"/>

    Then the XSLT saves and everything is fine.

    It does not seem to matter if the item has been created in the macro or not.

    What am I missing/doing wrong?

    Thanks

    TT

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Jul 31, 2010 @ 10:39
    Chriztian Steinmeier
    1

    Hi TT,

    When you save this, the $homeMenu variable will be null because the /macro/homeItem doesn't exist at that point - what may happen then, is that somehow  the $homePage variable ends up pointing to / since GetXmlNodeById() won't return anything meaningful, and then the apply-templates instruction sends the processor back into the template it's already in...

    Try to wrap the <ul> ... apply-templates ... </ul> in an if statement, to make sure that it's a meaningful id you're sending to GetXmlNodeById.

    /Chriztian 

  • TaoistTotty 246 posts 314 karma points
    Jul 31, 2010 @ 14:49
    TaoistTotty
    0

    Hi Chriztian

    Thanks for this, this was the solution.

    Also thanks for the reason why as well.

     Regards

    TT

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies