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?
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>
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 " "> ]>
<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>
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:
/Chriztian
Thanks, that worked. Not looking forward to wrapping my head around this xsl tomfoolery. Such a headache so far...
is working on a reply...