Copied to clipboard

Flag this post as spam?

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


  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 11:10
    Bob Jones
    0

    GetMedia example from video tutorial is throwing error on save..

    Hi,

    I am following Tim's video tutorial on Using Content and Media Pickers. I am up to the part where we are trying to use the GetMedia function from the Umbraco library to display media on the page, but I am getting an error when I am trying to save the file.

    I am fairly certain I have followed Tim's code line for line:

    ---------------------------------------------------------------------------------------

    <?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="/">
     
      <xsl:value-of select="$currentPage/data [@alias = 'mediaItem']"/>
        <xsl:copy-of select="umbraco.library:GetMedia($currentPage/data [@alias = 'mediaItem'], 'false')"/>
        </xsl:template>

    </xsl:stylesheet>

    -------------------------------------------------------------------------

    And here is the error stack trace:

    -------------------------------------------------------------------------

    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)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
    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)

    ---------------------------------------------------------------------------------------

    Anyone know what I'm doing wrong?

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 21, 2011 @ 11:17
    Sören Deger
    0

    Do you use Umbraco version 4.5+? Maybe you have the wrong xsl-scheme. Since 4.5+ have change the xsl-scheme.

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 11:19
    Bob Jones
    0

    I downloaded Umbraco this week so I'm going to guess its the latest, whichever that is?

    I am new to Umbraco and XSL, if I have the wrong schema then how do I fix this?

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 21, 2011 @ 11:28
    Sören Deger
    1

    You can see what version you have with the "About"-Button in the right-top border of your umbraco-backend.

     

    You can convert the old to new xsl-schema with the tool of this site:

    http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema

    Any examples with differences of both schemas you can find here:

    http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema

    Most of video tutorials shows the old xsl-schema only.

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 11:32
    Bob Jones
    0

    I am using v.4.7.1

    I only copied the GetMedia/ value of lines from Tim's code so surely I am not running an old schema? although I will double check this....

     

    .....oh, I think I see what you mean now! Thanks for the link

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 11:40
    Bob Jones
    0

    I have changed the code to this, which I think is in accordance with the new schema:

     <xsl:value-of select="$currentPage/mediaItem"/>
        <xsl:copy-of select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')"/>
        

    But I'm still getting the same error, can someone help?

    EDIT: I checked the skip testing button and saved, and was then able to visualise the XSLT successfully as in the video. So I guess that works then..

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 12:11
    Bob Jones
    0

     I am now stuck on the next step of the video tutorial where I have to set the image source to the path returned by get media.

    I have followed Tim's example:

    <img src="{umbraco.library:GetMedia($currentPage/mediaItem, 'false')}" />

    But when I load the page it says 'error reading xslt file'. I then tried to follow the examples on the new schema by Warren Buckley, as linked to in the previous answer to my post and came up with this:

     <h2Path </h2>
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')"/>
      <xsl:variable name "imgSrc" select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')" />
      <h2Image </h2>
      <img src="$imgSrc"/>

      The page loads without the error message for this but the image does not load. When I inspect the element in chrome a tooltip message next to the variable '$imgSrc' gives the following message: "Failed to load given URL"

    Any help appreciated

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 21, 2011 @ 12:37
    Sören Deger
    1

    You must write the variable into {}.

    Write this: 

    <img src="{$imgSrc}"/>

  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 12:48
    Bob Jones
    0

    When I add the curly brackets the page loads with an error message: "Error parsing XSLT file: \xslt\GetMediaItem.xslt"

     

    So I guess this brings me back full-circle to the original problem? I have tried to change the code according to the latest xsl schema but am getting errors when I try to save the xslt file in umbraco. I thought I had gotten past that by checking the 'ignore errors' box but with the added curly brackets as you suggested I am not back to the original error that I stated in my post.... unless it is another error altogether?!

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 21, 2011 @ 13:53
    Sören Deger
    0

    Have the documenttype of currentPage a property with alias mediaItem (datatype: mediapicker)?

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 21, 2011 @ 14:09
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 21, 2011 @ 14:10
    Tom Fulton
    0

    Hi Bob,

    The error might be because when you save the XSLT, it attempts to parse it for testing and may not have a value for GetMedia, which will fail if it's not passed a good value.  So you can try clicking the ignore errors checkbox and seeing if it works on the front end, or the better way is to do a test before your getmedia call:

    <xsl:if test="number($currentPage/mediaItem) &gt; 0">
      <xsl:variable name="imgSrc" select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')" />
      <h2Image </h2>
      <img src="{$imgSrc}"/>

    </xsl:if>

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft