Copied to clipboard

Flag this post as spam?

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


  • Eirik 25 posts 75 karma points
    Jul 24, 2012 @ 15:38
    Eirik
    0

    Render image with XSLT

    Hi,

    Version: 4.7.1.1

    after searching for hours on the forum and google I ended up here to ask the questions so many other people asked before. I am still not able to render images with XSLT.

    I have added some images to the Media-library. First I added them to a folder, but just to make it easier I added them to the root. There is a document type called Styremedlem with several properties. The property for the image is called boardImage and is of the type MediaPicker. I have tried at least 20 different versions of XSLT from the forum to render an image, but still no success.

     

    The XSLT looks like this:

     

    <xsl:variable name="mediaId" select="number($currentPage/boardImage)" />

    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" /> 

    This returns in the "XSLT-editor" an exception:

    Error occured

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

    ..

    ..

     

    I have other fields in the same XSLT which renders perfectly.

    Just as a test I wrote the XSLT below to see if its possible to get out the ID for the image, and this returns the ID correctly.<xsl:value-of select="boardImage"/> 

     

    Thank You!

     

    Cheers,

    Eirik

  • Alex Skrypnyk 6175 posts 24176 karma points MVP 8x admin c-trib
    Jul 24, 2012 @ 16:02
    Alex Skrypnyk
    0

    Hi Eirik,

    Why you need number function here ?

    <xsl:variable name="mediaId" select="number($currentPage/boardImage)" />

    We always use string, example:

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

     

    Thanks,

    Alex

  • Eirik 25 posts 75 karma points
    Jul 24, 2012 @ 16:09
    Eirik
    0

    Hi Alex,

    thanks for your reply.

    When I use your example I get an exception in the "XSLT-editor" when saving.

    Error occured

    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 umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    Thank you,

    Eirik

  • Alex Skrypnyk 6175 posts 24176 karma points MVP 8x admin c-trib
    Jul 24, 2012 @ 16:17
    Alex Skrypnyk
    0

    Are you sure that you pass media ID to the method?

     

  • Eirik 25 posts 75 karma points
    Jul 24, 2012 @ 16:24
    Eirik
    0

    Thats what I tried to do here: <xsl:variable name="mediaId" select="number($currentPage/boardImage)" />

    And then use the mediaid variable further on.

    Your way however this should not be necessary I guess, and I could use the variable mediaNode. but also in this case I get the exception.


    Eirik


  • Alex Skrypnyk 6175 posts 24176 karma points MVP 8x admin c-trib
    Jul 24, 2012 @ 16:39
    Alex Skrypnyk
    0

    please, see in add_data/umbraco.config what contains in boardImage property

  • Eirik 25 posts 75 karma points
    Jul 24, 2012 @ 17:29
    Eirik
    0

    I checked, and yes it contains the boardImage property.

    I guess that is verified since <xsl:value-of select="boardImage"/> prints the ID of the boardImage correctly.

     

    Eirik

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 24, 2012 @ 17:41
    Dennis Aaen
    0

    Hi Erik,

    Did you find a solution to your problem with the image,

    When I work with images in Umbraco I always print them like Alex mentioned in a previous post, but I always do a check on the media picker to check if it is empty.

    <xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/imageAlias, 0)"/>

    <xsl:iftest="$media">
           
    <imgsrc="{$media/umbracoFile}"alt="{$media/altText}"/>
    </xsl:if>

    Hope this can help you further if you have not already found a solution,

    /Dennis

  • Eirik 25 posts 75 karma points
    Jul 24, 2012 @ 17:54
    Eirik
    0

    Hi Dennis,

    thank you for following up. No, I didnt find the solution.

    Yes, I will also implement this test to see if the media picker is empty. However, my problem starts before this. My problem starts at your first statement <xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/imageAlias, 0)"/>

    The name of my propety (which is of the type media picker) is boardImage, so the my statement is exactly like this <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/boardImage, 0)"/>

    The result when I try to save the XSLT it failes and prints:

    Error occured

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

     

    Eirik

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 24, 2012 @ 18:06
    Dennis Aaen
    0

    Hi Erik,

    Okay donĀ“t know if this small change will do the trick,

    <xsl:variablename="media"select="umbraco.library:GetMedia($currentPage/imageAlias, 0)"/>

    <xsl:iftest="$media!=''>
           
    <imgsrc="{$media/umbracoFile}"alt="{$media/altText}"/>
    </xsl:if>

    I forgot the add the not equal to empty statement to the if

    I hope this will do the trick for you

    /Dennis

  • Eirik 25 posts 75 karma points
    Jul 24, 2012 @ 19:27
    Eirik
    0

    Thanks again for your reply Dennis.

    After a lot of struggling I found the problem and the rendering of images works fine :-)

    The problem was, which I dont fully understand yet, that I had to remove the $currentPage. I am running a for-each (<xsl:for-each select="$currentPage/*) so it looks like $currentPage must not be used later on. I must look more into this.

     

    Anyway, the problem was solved. Thank you Dennis and Alex for your help

     

    Cheers, Eirik

Please Sign in or register to post replies

Write your reply to:

Draft