0

Searching for an error with GetMedia on Forum, I read that the variable i give the functions is not an integer.

Here is the error: System.OverflowException: Value was either too large or too small for an Int32.

I check my variable:

<xsl:value-of select="$currentPage/image" />

The output was:

1663

then i try this:

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

It returns me the error I wrote you above. If i wrote 1663 instead of $currentPage/image it works but then it's hardcoded and it musn't be hardcoded.

Here my xslt

<xsl:template match="/">

<!-- start writing XSLT -->
<xsl:value-of select="$currentPage/image" />
<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />
<div class="tfirst">
<p>
    <!--xsl:if test="not($media/error)">
        <img src="{$media/umbracoFile}" class="left timg" />
    </xsl:if-->
    <div class="ttext">
        <h2><xsl:value-of select="umbraco.library:StripHtml($currentPage/title)" /></h2>
        <xsl:value-of select="$currentPage/abstractText" disable-output-escaping="yes" />
    </div>
</p>
</div>
<div class="ttext">
<xsl:if test="$currentPage/showMultipleColumns='1'">
    <xsl:attribute name="class">showMultipleColumns</xsl:attribute>
</xsl:if>
<xsl:value-of select="$currentPage/bodyText" disable-output-escaping="yes" />
</div>

</xsl:template>

Thank you for your help. Benjamin

Edit------------------

I've tried to add a if test but now it give me another error if i replace $currentPage/image by 1663 : System.Xml.Xsl.XslTransformException: To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.

If i let the $currentPage/image I always have: System.OverflowException: Value was either too large or too small for an Int32.

Here is the xslt:

<xsl:variable name="atest" select="umbraco.library:GetMedia($currentPage/image, false())" />
<xsl:variable name="media">
    <xsl:if test="$currentPage/image &gt; 0">
        <xsl:value-of select="$atest" />
    </xsl:if>
</xsl:variable>

Edit2------------

Trying this below always getting the error: System.OverflowException: Value was either too large or too small for an Int32.

<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />
<xsl:if test="$media">
  <img src="{$media/umbracoFile}" class="left timg" />
</xsl:if>
Benjamin
  • 31
  • 6

2 Answers2

0

You need to check if your $currentPage/image is > 0 before you call the umbraco.Library:GetMedia() function. I can't remember why it was like that, but I've encountered the same issue a few years ago and if I recall it correctly, there was a reason for doing so.

try this:

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

EDIT:

I'm confused with the check you need to add in the Umbraco Macro Editor with this. Rendering an image should be as simple as this:

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

 <xsl:if test="$media">
        <xsl:variable name="url" select="$media/umbracoFile" />
        <xsl:variable name="width" select="$media/umbracoWidth" />
        <xsl:variable name="height" select="$media/umbracoHeight" />
        <img src="{$url}" width="{$width}" height="{$height}" />
 </xsl:if>
Martijn van der Put
  • 4,062
  • 1
  • 18
  • 26
  • Hi, I tried it and now is telling me this: System.Xml.Xsl.XslTransformException: To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function. For more details see the edit part in my post. – Benjamin May 29 '13 at 15:26
  • Your test is wrong, you have switched the order of your lines in your test. Try the exact order of my example. – Martijn van der Put May 29 '13 at 15:34
  • I've tried your example, but always this error about int32. See my edit 2 – Benjamin May 30 '13 at 02:23
0

Thanks for your help. Found my problem solution. Because my image is not mandatory (yes something that i should tell before). I just did that:

<xsl:if test="$currentPage/image &gt; 0">
  <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />
  <xsl:if test="not($media/error)">
    <img src="{$media/umbracoFile}" class="left timg" />
  </xsl:if>
</xsl:if>

Now it just works fine. Thank you for your help. Have a great day. Benjamin

Benjamin
  • 31
  • 6