Copied to clipboard

Flag this post as spam?

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


  • Joey 20 posts 44 karma points
    Oct 01, 2011 @ 08:43
    Joey
    0

    System.OverflowException: Value was either too large or too small for an Int32.

    Whenever I try to save the following xslt it throws an error. I cannot figure out what is wrong. If I check the "Skip testing" button it saves and when I go to the live page to see the macro run it runs just fine.. Why is umbraco throwing this error for this code?

     

    <?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" xmlns:filesystem="urn:filesystem"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets filesystem ">


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

    <xsl:param name="currentPage"/>
    <xsl:variable name="cssClass" select="/macro/cssClass"/>

    <xsl:template match="/">


    <!-- start writing XSLT -->
    <xsl:if test="$currentPage">

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/primaryImage, 0)" />

    <xsl:if test="$media">
    <img src="{$media/umbracoFile}" alt="{$media/altText}" class="{$cssClass}" />
    </xsl:if>
    </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Oct 01, 2011 @ 12:53
    Chriztian Steinmeier
    0

    Hi Joey,

    When you save the file, Umbraco will actually run the macro to test for errors (basically to test if it is a valid XSLT (XML) file - but it will point $currentPage to the top /root/ node, which means that when you call the GetImage() extension, there is no valid media ID in the primaryImage property, so the extension fails.

    It's easy to fix, as you just have to make sure that the call is only executed if there's a value in the primaryImage field. It's also good practice to check the result from the GetMedia() call - if the ID no longer exists you'll get an <error> element back, so we check that too:

    <xsl:template match="/">
        <!-- Only if primaryImage has content -->
        <xsl:apply-templates select="$currentPage/primaryImage[normalize-space()]" />
    </xsl:template>
    
    <xsl:template match="primaryImage">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" />
        <xsl:if test="$mediaNode[not(error)]">
            <img src="{$mediaNode/umbracoFile}" alt="{$mediaNode/altText}" class="{$cssClass}" />
        </xsl:if>
    </xsl:template>

    /Chriztian 

  • Joey 20 posts 44 karma points
    Oct 02, 2011 @ 06:41
    Joey
    0

    Thanks, that worked. Not looking forward to wrapping my head around this xsl tomfoolery. Such a headache so far...

Please Sign in or register to post replies

Write your reply to:

Draft