I'm using the repeatable custom content package to iterate through some items on my website homepage. I've got this working fine for all of the text datatypes in the repeater, but one of the datatypes is a mediapicker item and I've no idea how to include this datatype in the output in XSLT.
Could someone suggest how to do this, or point me in the direction of an example of a mediapicker datatype being called from XSLT in this kind of situation?
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)
It doesn't seem to be getting a valid integer on this part:
Done that Jeroen, but nothing appears at all (nothing in the HTML at all, not just an incorrect image path etc). There is an image selected for each item in the repeater - I've double checked by editing them - but it's as if it doesn't recognise that there is anything there.
Hmm I don't know what the problem is then. You can check if the id's are really saved in the xml file. In your Umbraco website go to /data/umbraco.config and go to the node in which you placed the mediapicker. Look for <data alias="promoImage"></data> and see if there is a id in it. This should be the id of the selected media item. If it's not there something went wrong with saving the item. Did you publish the page because you need to do that in order to save the data to the xml file.
Error occuredSystem.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)
I looks like the same issue as this thread.
The only way to solve it for now, is by hardcoding the following node id. Also the 'true' must be changed to a 1.
Hello. I think that maybe the value from mediapicker is not an integer. I tried to put in the value as "numbers" and that worked. Is there any way to convert the @alias id to a integer? (I'm very new to this).
In xml, everything is a string so it's not a case of having to cast variables.
The problem with "the value was too large or small..." is that when saving the xsl parser checks your code against the topmost node. If your top node doesn't have the data type that you're checking against an error will be thrown. You can get around this by checking the box to disable error checking, but this can bring other problems.
You basically need to wrap a check around GetMedia, and call it only if there is a value.
I must be really bad at this! I have wrapped it in a check and the error message does not show anymore. However i do not get the expected result (a displayed image). If i print there is a value (at the bottom of the code below) displayed. Obviously there is a value. My test shows the value of 1259.
Output media picker item in XSLT
Hi,
I'm using the repeatable custom content package to iterate through some items on my website homepage. I've got this working fine for all of the text datatypes in the repeater, but one of the datatypes is a mediapicker item and I've no idea how to include this datatype in the output in XSLT.
The code I have is as follows:
Could someone suggest how to do this, or point me in the direction of an example of a mediapicker datatype being called from XSLT in this kind of situation?
Thanks folks!
Try
for the path to the image
Dan
Maybe the following code helps althoug it's inline xslt:
I found it at http://umbraco.org/documentation/books/inline-xslt
Thanks, I think I'm almost there - I've tried the following:
But I get an error:
It doesn't seem to be getting a valid integer on this part:
Any ideas?
I think it should be:
It tests your xslt against the root node, do if the property doesn't exist on your root node you get the error
Try
Dan
@jeroen
oops, didn't scroll and check that!
Is correct.
@Dan You're basically using getMedia to get the media node by passing in the id contained in "promoImage", then if you consider the whole
umbraco.library:GetMedia($currentPage/data[@alias='promoImage'], 'false')
to be a node,
Gets the part of the media node containing the url
Dan
Same error :(
Actually this doesn't error now, but it returns nothing, as if the value of
Is empty. It's not though - there is definitely an image in there.
Hmm you can test it by the code I provided before:
Place this on the template of the page and it should display the image...
Done that Jeroen, but nothing appears at all (nothing in the HTML at all, not just an incorrect image path etc). There is an image selected for each item in the repeater - I've double checked by editing them - but it's as if it doesn't recognise that there is anything there.
Hmm I don't know what the problem is then. You can check if the id's are really saved in the xml file. In your Umbraco website go to /data/umbraco.config and go to the node in which you placed the mediapicker. Look for <data alias="promoImage"></data> and see if there is a id in it. This should be the id of the selected media item. If it's not there something went wrong with saving the item. Did you publish the page because you need to do that in order to save the data to the xml file.
If you're using repeatable custom content, inside the foreach loop it won't be "$currentPage", but
Now try
Dan
I'm just trying to debug this a little. Doing the following:
Does output a valid media node id - it outputs:
So something is working. It just seems as if it can't get the file name of the file in that media node.
Yay! Dan, thank you so much (again!) that's done the job.
There's a missing quote in your solution, but here it is in all its glory for future XSLT strugglers:
Thanks you both for your help, it's much appreciated!
Have you tried
using . is the same as current()
Dan
oops, too late! Glad you got it sorted
Dan
Hi All,
I have the same problem with the error. I have a mediapicker and in my XSLT the output of a MediaPicker is a node-id.
The above output is 1419. So far so good, but when I put this into the following line:
I get a terrible error:
I looks like the same issue as this thread.
The only way to solve it for now, is by hardcoding the following node id. Also the 'true' must be changed to a 1.
Do I need to cast something? Looks like the GetMedia does not accept strings as parameter.
I am using Umb 4.0.2.1
Nico
Hello. I think that maybe the value from mediapicker is not an integer. I tried to put in the value as "numbers" and that worked. Is there any way to convert the @alias id to a integer? (I'm very new to this).
In xml, everything is a string so it's not a case of having to cast variables.
The problem with "the value was too large or small..." is that when saving the xsl parser checks your code against the topmost node. If your top node doesn't have the data type that you're checking against an error will be thrown. You can get around this by checking the box to disable error checking, but this can bring other problems.
You basically need to wrap a check around GetMedia, and call it only if there is a value.
That should get rid if your error.
Dan
I must be really bad at this! I have wrapped it in a check and the error message does not show anymore. However i do not get the expected result (a displayed image). If i print there is a value (at the bottom of the code below) displayed. Obviously there is a value. My test shows the value of 1259.
<xsl:if test="string(./data [@alias='colImgBottom3']) != '' ">
<img>
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia(./data [@alias='colImgBottom3'], 'false')"/>
</xsl:attribute>
</img>
</xsl:if>
<xsl:value-of select="$currentPage/data [@alias = 'colImgBottom3']"/>
To actually get the image url you need the following:
as getMedia gets the whole media node xml, not just the url
Dan
Hi Micke, You need to add the path-part of the media item you fetch:
>Tommy
Eureka! That and the @currentPage did it!
Thank you very much! My final row goes like this:
is working on a reply...