Copied to clipboard

Flag this post as spam?

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


  • Marc 21 posts 40 karma points
    Apr 26, 2011 @ 00:34
    Marc
    0

    Use variable for GetXmlNodeById

    Hi I tried to use variable for GetXmlNodeById in this XSLT below.I'm using "deptrootid" as variable, i verify i can get the page id & put it into variable "deptrootid". But when I want to use it in GetXmlNodeById, I got this error message:

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    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 (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    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)

     

    below is the XSLT:

     

    <?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="minLevel" select="1"/>

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="40"/>
    <xsl:template match="/">
        
    <!-- Identify the Dept root ID -->
    <xsl:variable name="deptrootid">
        <xsl:if test="$currentPage/@level &gt; $minLevel">
         
              <xsl:for-each select="$currentPage/ancestor::* [@level &gt; $minLevel and string(umbracoNaviHide) != '1']">
                <xsl:if test="@level = 3">
                  <xsl:value-of select="@id"/>
                </xsl:if>          
              </xsl:for-each>      

         </xsl:if>

    </xsl:variable>
        
    <!-- Draw the tree start from Dept root ID -->
        
    <div id="sitemap">
    <xsl:call-template name="drawNodes">  
      <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($deptrootid)"/>
    </xsl:call-template>
    </div>
    </xsl:template>

    <xsl:template name="drawNodes">

    ....

    ....

    ....

    </xsl:template>

    </xsl:stylesheet>

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Apr 26, 2011 @ 03:49
    Tom Fulton
    0

    Hi,

    You can usually fix that error by wrapping the offending line in an xsl:if statement to test that the parameter isn't empty.  When you save the XSLT Umbraco parses it for testing, and can't fill in variables in some conditions.

    So try something like

    <xsl:if test="$deptrootid &gt; 0">
    <xsl:call-template name="drawNodes">  
      <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($deptrootid)"/>
    </xsl:call-template>
    </xsl:if>

    Also not sure exactly what you are doing in the first for-each loop, but instead of looping and checking for level 3 each time you can simply add @level = 3 to your XPath and avoid doing the loop

    <xsl:value-of select="$currentPage/ancestor::* [@level = 3 and string(umbracoNaviHide) != '1']/@id" />

    Hope this helps,
    Tom

  • praveity 100 posts 125 karma points
    Apr 26, 2011 @ 13:48
    praveity
    0

    Hi Marc,

    You should follow as Tom has told. Most of the time xslt parser return "Value was either too large or too small for an Int32." when we use variables. So its better to check if really do have value in it as 

    <xsl:if test="$deptrootid &gt; 0">
    <!-- your code here -->
    </xsl:if>

     

  • Marc 21 posts 40 karma points
    Apr 26, 2011 @ 17:55
    Marc
    0

    Yes it works. And I don't know you can just jump to top level ancestor. Thank you Tom.

Please Sign in or register to post replies

Write your reply to:

Draft