Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Jan 25, 2011 @ 11:31
    Dan
    0

    Sitemap from level 2

    Hi,

    I'm using a standard sitemap XSLT template, but want it to start on level 2 rather than level 1.  Here is the code, starting at level 1, which works perfectly:

    <?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" 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:variable name="maxLevelForSitemap" select="4"/>

    <xsl:template match="/">
      <xsl:call-template name="drawNodes">  
        <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>  
      </xsl:call-template>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
      <xsl:if test="umbraco.library:IsProtected($parent/@id,
    $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id,
    $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)"
    >
        <ul>
          <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]">
            <li>  
              <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
              </a>  
              <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   
                <xsl:call-template name="drawNodes">    
                  <xsl:with-param name="parent" select="."/>    
                </xsl:call-template>  
              </xsl:if>
            </li>
          </xsl:for-each>
        </ul>
      </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    But when I change this...

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>

    To this...

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=2]"/>

    I get an error:

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, IList`1 parent)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    Can anyone suggest what's going wrong?

    Thanks!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 25, 2011 @ 12:42
    Jan Skovgaard
    0

    Hi Dan

    try adding '' around the 2. So it reads @level='2'

    I think that should help.

    /Jan

  • Dan 1288 posts 3921 karma points c-trib
    Jan 25, 2011 @ 16:22
    Dan
    0

    Thanks Jan, but it still gives the same error, as does number(2) and number('2').  This is actually for a multi-tier nested navigation system, so I've just used the Flexible Navigation package and that sorted me out, although the XSLT is way more complex in there than I think it should be now.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 25, 2011 @ 16:25
    Jan Skovgaard
    0

    Hi Dan

    Ok, what happens if you check the "skip error testing" and save the file? Does it then still fail on your website?

    /Jan

  • Dan 1288 posts 3921 karma points c-trib
    Jan 25, 2011 @ 16:30
    Dan
    0

    I tried that actually and it just gave the standard: Error parsing XSLT file.

  • Stuart Burrows 61 posts 110 karma points
    Jan 25, 2011 @ 16:35
    Stuart Burrows
    0

    Are you getting this error when you are visualising against the homepage?

    I've tested your code against my setup and this it is only when I test using a page whose level is less than 2 that I get the error. This is happening because you are (understandably) using ancestor-or-self here:

     <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>

    This will throw an error as nothing matches.

    A workaround could be to keep the initial match the same but change:

     

    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]">

     

    to:

    <xsl:for-each select="$parent/* [(@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap) and @level &gt;= 2]">

     

    Hope this helps!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 25, 2011 @ 16:35
    Jan Skovgaard
    0

    Have you tried using the ?umbracodebugshowtrace=true when you're viewing the page to see if you get some better error description?

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft