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:
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)
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:
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"
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?!
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:
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 " "> ]>
<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?
Do you use Umbraco version 4.5+? Maybe you have the wrong xsl-scheme. Since 4.5+ have change the xsl-scheme.
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?
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.
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
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..
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:
<h2> Path </h2>
<xsl:value-of select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')"/>
<xsl:variable name = "imgSrc" select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')" />
<h2> Image </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
You must write the variable into {}.
Write this:
<img src="{$imgSrc}"/>
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?!
Have the documenttype of currentPage a property with alias mediaItem (datatype: mediapicker)?
This is another example to use umbraco.library GetMedia:
http://blog.leekelleher.com/2010/08/11/how-to-use-umbraco-library-getmedia-in-xslt-for-umbraco-v4-5/
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:
-Tom
is working on a reply...