Copied to clipboard

Flag this post as spam?

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


  • Jason Gochanour 3 posts 20 karma points
    Jun 12, 2009 @ 18:09
    Jason Gochanour
    0

    OverFlow Exception Dealing with GetMedia

    Hi,

    Do you see anything wrong with this chunk of code? I'm using it to pull in a random page specified with a contentRandom Macro parameter type. From there it grabs the URL and a image document property, makes a link, and tosses it on my homepage. It was working a second ago, but it mysteriously broke after I added some comments (and removing the comments keeps the brokenness #-o ). Here's the code.

    [code]

    ]>

    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:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:math="urn:schemas-hizi-nl:math"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
    exclude-result-prefixes="msxml Exslt.ExsltMath Exslt.ExsltStrings math umbraco.library">



























    [/code]

    and the error..

    [code]
    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 ImageURL(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, 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)
    [/code]

    It's got to be something with one of the umbraco library functions, I just don't know how to debug it. Any efficient way to debug umbraco XSLT?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jun 25, 2009 @ 20:37
    Lee Kelleher
    0

    Hi Jason,

    For a first sweep of debugging the XSLT, try adding "?umbDebugShowTrace=true" to the QueryString of your URL - that should give you a view of what macro XML (parameters) are being used with your XSLT.

    As for the OverflowException (Value was either too large or too small for an Int32) - you are correct in thinking that it is due to the umbraco.library methods.  My guess would be that the value being passed into either umbraco.library:GetMedia or umbraco.library:NiceUrl is not numeric.

    Try outputting the variables $StartNode and $ImageID - do this before you set the value of the $ImageURL variable, (as that might be throwing the exception).

    One last thing, I'm not sure what you are trying to do with the $Image variable.  The value of "/macro/StartNode/node/data/@bodyImage" doesn't seem like would return a value?! (unless I am mistaken)

    Let me know how it works out.

    Cheers,

    - Lee

  • Jamie Pollock 27 posts 102 karma points c-trib
    Jun 25, 2009 @ 20:58
    Jamie Pollock
    2

    Hi there,

    Lee is on the money, you need to check your value coming in, typically when I go through a several step process when using umbraco.library:GetMedia().

    <!-- create a variable to store the ID -->
    <xsl:variable name="mediaId" select="$StartNode/@id" />

    <!-- now check the ID is a number -->
    <xsl:if test="number($mediaId) &gt; 0">
    <!-- Now we know we have an ID, store the umbraco.library:GetMedia() in a variable, this way we can reuse it -->
    <!-- Note here we have an additional parameter, when set to false() it will return just that node, if set to true it will return that node and it's children, this is useful for getting media folders -->
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, false())" />

    <!-- Now check that the retrieved media url string has a length otherwise we will be outputting a blank string -->
    <!-- This is held in the "/data[@alias = 'umbracoFile']" as GetMedia returns a media node-->
    <xsl:if test="string-length($mediaNode/data[@alias = 'umbracoFile']) &gt; 0">
    <!-- output our safely found media url into our link, using inline XSLT between the {...} -->
    <a href="{$mediaNode/data[@alias = 'umbracoFile']}">
    <!-- Just like a content node you can retrieve a media node's @nodeName -->
    <xsl:value-of select="$mediaNode/@nodeName" />

    </xsl:if>
    </xsl:if>

    I hope this helps elaborate this a little more.

    I know it's not exactly what you're looking for, but it does show a safe way to get a media object, lol... I should read the topics more before blasting off into a detailed code example. :P

  • Olly Berry 47 posts 68 karma points
    Oct 22, 2009 @ 23:33
    Olly Berry
    0

    Thanks Lee/Jamie, think you just solved a problem I was having!

Please Sign in or register to post replies

Write your reply to:

Draft