Copied to clipboard

Flag this post as spam?

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


  • Luke Johnson 61 posts 80 karma points
    Jul 12, 2011 @ 00:32
    Luke Johnson
    0

    "Value was either too large or too small for an Int32" with GetMedia

    I am trying to get images to display with XSLT. The video tutorial must be pre-4.5.1 because it is using the old syntax $currentPage/data [@alias = 'property'], etc. I am getting this error:

    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) 
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) 
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) 
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) 
    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) 

    Here is the code I am attemping to use. "facultyPhoto" is the page field of the media picker. The ID number of my photo shows up on the page, but I can't get the actual picture to show.

    <xsl:template match="/">
      <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/facultyPhoto, 0)" />
          <xsl:if test="$media">
            <img src="{$media/umbracoFile}" alt="{$media/altText}" />
          </xsl:if>
      
    </xsl:template>

    Something must be wrong in my understanding of the syntax. (I am using syntax found here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 12, 2011 @ 01:31
    Tom Fulton
    0

    Hi Luke,

    You should be able to fix this by adding an if statement around the GetMedia call, shown below.  When you save an XSLT file Umbraco attempts to validate it through the XSLT parser, and some calls (like GetMedia, NiceUrl) will fail if they are not passed a value.  You can always test this by clicking the Ignore Error checkbox and saving it, then checking the front end of the website and seeing if it works.

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

    Hope this helps,
    Tom

  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 12:07
    Max Mumford
    0

    As far as I know the URL of an image property is saved as a sub property of the image property itself along with widths and heights etc... for example:

    $currentPage/facultyPhoto/umbracoFile

    I might be wrong but it would be worth a go trying it out :)

    Also if I am right that the URL itself is saved within the facultyPhoto property, try outputting the facultyPhoto property to a textarea, like so:

    <textarea>

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

    </textarea>

    I wanted to give something back to the forums as I have had so much help, sorry if all the above information is wrong, I am still a baby umbracoer :P

    Max.

  • Luke Johnson 61 posts 80 karma points
    Jul 12, 2011 @ 17:54
    Luke Johnson
    0

    Thank-you Max and Tom! Your input got me going in the right direction. I found a blog that laid it out nicely:

    <xsl:template match="/">
        <xsl:variable name="mediaId" select="number($currentPage/mediaId)" />
        <xsl:if test="$mediaId > 0">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
            <xsl:if test="$mediaNode/umbracoFile">
                <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{umbracoHeight}" width="{umbracoWidth}" />
            </xsl:if>
        </xsl:if>
    </xsl:template>

    From: http://blog.leekelleher.com/2010/08/11/how-to-use-umbraco-library-getmedia-in-xslt-for-umbraco-v4-5/#comment-686

  • Max Mumford 266 posts 293 karma points
    Jul 12, 2011 @ 18:24
    Max Mumford
    0

    No problem, glad I could help and you figured it out.

    Max

Please Sign in or register to post replies

Write your reply to:

Draft