Copied to clipboard

Flag this post as spam?

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


  • seanrock 262 posts 483 karma points
    Jun 23, 2010 @ 00:32
    seanrock
    0

    why does this not work

    <xsl:variable name="mediaFolderId" select="$homeNode/data[@alias='headerImageFolder']" />
    <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaFolderId, 'true')" />

    homeNode is a node above/or the current node and headerImageFolder is a mediapicker property (a media folder is selected) and this contains the id of the selected folder. When i save it i get the following error. However if i hard code the value instead of using the mediafolderId variable in the call to GetMedia it works fine.

     

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32. 
    at System.Convert.ToInt32(Double value) 
    at System.Double.System.IConvertible.ToInt32(IFormatProvider provider) 
    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 Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) 
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) 
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) 
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results) 
    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)

    Regards

    Sean

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jun 23, 2010 @ 01:39
    Stefan Kip
    0

    I think the problem is, that XSLT doesn't know if $mediaFolderId will be a valid integer, could you try this:

    <xsl:variable name="mediaFolderId" select="number($homeNode/data[@alias='headerImageFolder'])" />

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jun 23, 2010 @ 01:40
    Sebastiaan Janssen
    0

    You should probably check to see if the mediaFolderId returns a result (even if you know that it should). See Lee Kelleher's blog post on how to use GetMedia, it's excellent!

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jun 23, 2010 @ 01:42
    Stefan Kip
    0

    Sorry, that's not correct, use this instead:

    <xsl:variable name="mediaFolderId" select="number($homeNode/data[@alias='headerImageFolder'])" />
    <xsl:if test="$mediaFolderId &gt; -1">

      <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaFolderId, 'true')" />
    <!-- the rest of your code -->


    </xsl:if>

    Just another reason to use .NET instead of XSLT ;-)

  • seanrock 262 posts 483 karma points
    Jun 23, 2010 @ 11:54
    seanrock
    0

    thanks i'll get that a try

  • Sajid Riaz 142 posts 165 karma points
    Jun 23, 2010 @ 12:25
    Sajid Riaz
    0

    Hi seanrock,

    I've noticed that in xslt if you declare a variable set to an id of a node and you dont specify the if test, as kipusoep mentions above, i've almost always get the error you showed above.

  • Sajid Riaz 142 posts 165 karma points
    Jun 23, 2010 @ 12:28
    Sajid Riaz
    0

    seanrock,

     

    I've posted an issue something similar to you my xslt is as follows:

    <xsl:param name="currentPage"/>
    <xsl:variable name="ID" select="$currentPage/data [@alias = 'galleryImages']"/>
    <xsl:template match="/">

    <!-- start writing XSLT -->
    <xsl:if test="$ID &gt; 0">
    <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($ID, true())"/>
    <xsl:for-each select="$mediaItems/node">      
    <img>
        <xsl:attribute name="src">
        <xsl:text>/umbraco/imagegen.ashx?image=</xsl:text>
        <xsl:value-of select="current()/data[@alias='umbracoFile']"/>
        <xsl:text>&amp;width=300</xsl:text>
        </xsl:attribute>
    </img>
    </xsl:for-each>

     

    where galleryImages is the mediapicker property set to a sub folder under the media folder.

Please Sign in or register to post replies

Write your reply to:

Draft