Copied to clipboard

Flag this post as spam?

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


  • Richard Kingston 46 posts 69 karma points
    Dec 02, 2010 @ 12:39
    Richard Kingston
    0

    Issue with GetMedia call and variable as Int32

    Hi all,

    Using the Umbraco interface, I'm having an issue passing a variable into the GetMedia function in the code below. If I hardcode the value 1065, the code works fine. If I pass in $mediaCollection, it fails to validate, but the value of the variable is 1065.

    The interesting part is that if I select the checkbox to ignore errors, the XSLT file saves OK and it works. But with the box unchecked, it reports the error:

    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, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
    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)

    The XSLT code is here:


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <textarea rows="40" cols="10">
    <xsl:value-of select="macro/*" />
    </textarea>
    <xsl:variable name="mediaCollection" select="macro/mediaCollection/Folder/@id" />
    <xsl:value-of select="$mediaCollection"/>
    <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($mediaCollection, 1)"/>

    <div id='coin-slider'>
        <xsl:for-each select="$mediaItems/*">
        <xsl:if test="@id!=$mediaCollection">
                    <a>
                        <xsl:attribute name="href"><xsl:value-of select="linkURL"/></xsl:attribute>
                        <img>
                            <xsl:attribute name="src"><xsl:value-of select="umbracoFile"/></xsl:attribute>
                        </img>
                        <span>
                            <xsl:value-of select="@nodeName"/>
                        </span>
                   </a>
        </xsl:if>
        </xsl:for-each>
    </div>
    </xsl:template>

    </xsl:stylesheet>


    I've found other topics in the forums about similar issues, but haven't been able to resolve mine using their suggestions. This might be my understanding though.

    It's not preventing me from progressing with my projcet, but obviously something is wrong, and it's best not to sweep these things under the carpet in my experience - they generally come back to bite.

    Can anyone help?

    Thanks

    Rich

  • Richard Kingston 46 posts 69 karma points
    Dec 02, 2010 @ 12:40
    Richard Kingston
    0

    PS - ignore the text area - that was for debugging purposes.

  • Sebastian Dammark 581 posts 1385 karma points
    Dec 02, 2010 @ 12:44
    Sebastian Dammark
    1

    I think it happens when you're using a variable that might not be present at the time when saving.

    But when you run it on the actual website it'll work just fine.
    So it's not a problem with your XSLT.

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Dec 02, 2010 @ 12:48
    Stefan Kip
    0

    Try this:

    <xsl:variable name="mediaItems" select="umbraco.library:GetMedia(number($mediaCollection), 1)"/>

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 02, 2010 @ 13:36
    Kim Andersen
    1

    Try changing this line:

    <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($mediaCollection, 1)"/>

    to this:

    <xsl:if test="macro/mediaCollection/Folder/@id != ''">
    <xsl:variable
    name="mediaItems" select="umbraco.library:GetMedia($mediaCollection, 1)"/>
    </xsl:if>

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft