I've been working on this for about 3 hours now following various links in the forums and getting nowhere.
On my document I have a media picker called newsItem1. There will be a newsItem2 and a newsItem3.
I have some code that allows a user to pick a nose as a news item and it will then create a link with the page's heading and a date which is set by the user.
I want to add an image next to each news item which is picked from the media folder by way of a media picker. I think the code I have is very close but doesn't seem to add the image in - please help!
When I go to save it, it throws up the following error:
Error occured
System.OverflowException: Value was either too large or too small for an Int32. at System.Convert.ToInt32(Double value) 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 newsImg1(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, XmlWriter writer) 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)
Thanks Jeroen, but as I'm using xslt an umbraco tag won't work (unless yuou know of a way to sneak it in?)
I'm trying a slightly differnet approach now as I seem to be going around in circles. I'm popping the media picker in the news item document so you pick the media item with each story to see if it will work this way. I'm a little bit closer as I can get it to now display the id for the image I want to use (<img src="nodeid"... />). I think it must be something do with a GetMedia tag or something, but I'm having trouble structuring the syntax in the correct way... Please can someone tell me what I'm doing wrong?
but it said that "System.Xml.Xsl.XslTransformException: Extension object 'urn:umbraco.library' does not contain a matching 'GetMedia' method that has 1 parameter(s). "
Any help would be much appreciated as my poor brain hurts.
Trouble with a media picker
Hi Everyone,
I've been working on this for about 3 hours now following various links in the forums and getting nowhere.
On my document I have a media picker called newsItem1. There will be a newsItem2 and a newsItem3.
I have some code that allows a user to pick a nose as a news item and it will then create a link with the page's heading and a date which is set by the user.
I want to add an image next to each news item which is picked from the media folder by way of a media picker. I think the code I have is very close but doesn't seem to add the image in - please help!
Code below:
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:variable name="pageId1" select="string($currentPage/data[@alias='item1link'])"/>
<xsl:variable name="pageId2" select="string($currentPage/data[@alias='item2link'])"/>
<xsl:variable name="pageId3" select="string($currentPage/data[@alias='item3link'])"/>
<xsl:variable name="newsImg1" select="umbraco.library:GetMedia($currentPage/data[@alias='newsImage1'], 0)" />
<xsl:template match="/">
<p class="newsitem">
<xsl:variable name="newsImg1" select="umbraco.library:GetMedia($currentPage/data[@alias='newsImage1'], 0)" />
<xsl:if test="string($newsImg1)!=''">
<img src="{$newsImg1/umbracoFile}" alt="{$newsImg1/altText}" class="floatleft" width="60" height="45" />
</xsl:if>
<a href="{umbraco.library:NiceUrl($pageId1)}"><xsl:value-of select="string(umbraco.library:GetXmlNodeById($pageId1)/data [@alias = 'heading'])"/>a><br /> <xsl:value-of select="umbraco.library:FormatDateTime(umbraco.library:GetXmlNodeById($pageId1)/./data[@alias='datepublished'],'dd MMMM yyyy')"/>p>
<hr width="94%" />
<p class="newsitem"><a href="{umbraco.library:NiceUrl($pageId2)}"><xsl:value-of select="string(umbraco.library:GetXmlNodeById($pageId2)/data [@alias = 'heading'])"/>a><br /> <xsl:value-of select="umbraco.library:FormatDateTime(umbraco.library:GetXmlNodeById($pageId2)/./data[@alias='datepublished'],'dd MMMM yyyy')"/>p>
<hr width="94%" />
<p class="newsitem"><a href="{umbraco.library:NiceUrl($pageId3)}"><xsl:value-of select="string(umbraco.library:GetXmlNodeById($pageId3)/data [@alias = 'heading'])"/>a><br /> <xsl:value-of select="umbraco.library:FormatDateTime(umbraco.library:GetXmlNodeById($pageId3)/./data[@alias='datepublished'],'dd MMMM yyyy')"/>p>
<p> p>
xsl:template>
xsl:stylesheet>
<xsl:variable name="newsImg1" select="umbraco.library:GetMedia($currentPage/data[@alias='newsImage1'], 0)" />
to
<xsl:variable name="newsImg1" select="umbraco.library:GetMedia($currentPage/newsImage, 0)" />
Thanks for the quick response!
When I go to save it, it throws up the following error:
Error occured
System.OverflowException: Value was either too large or too small for an Int32.
at System.Convert.ToInt32(Double value)
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 newsImg1(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, XmlWriter writer)
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)
sorry
<xsl:variable name="newsImg1" select="umbraco.library:GetMedia($currentPage/newsImage1, 0)" />
Sorry should have mentioned I spotted that error and corrected it before trying...
It throws up that error when I use:
<xsl:variable name="newsImg1" select="umbraco.library:GetMedia($currentPage/newsImage1, 0)" />
Maybe not related to this, but if you use DAMP you can store the complete media xml instead of only the id.
You could also try the umbraco:image control.
Jeroen
Thanks Jeroen, but as I'm using xslt an umbraco tag won't work (unless yuou know of a way to sneak it in?)
I'm trying a slightly differnet approach now as I seem to be going around in circles. I'm popping the media picker in the news item document so you pick the media item with each story to see if it will work this way. I'm a little bit closer as I can get it to now display the id for the image I want to use (<img src="nodeid"... />). I think it must be something do with a GetMedia tag or something, but I'm having trouble structuring the syntax in the correct way... Please can someone tell me what I'm doing wrong?
<xsl:variable name="pageId1" select="string($currentPage/data[@alias='item1link'])"/>
<xsl:variable name="pageId2" select="string($currentPage/data[@alias='item2link'])"/>
<xsl:variable name="pageId3" select="string($currentPage/data[@alias='item3link'])"/>
<xsl:template match="/">
<p class="newsitem">
<img src="{umbraco.library:GetXmlNodeById($pageId1)/data [@alias = 'newsImage']}" class="floatleft" width="60" height="45" />
<a href="{umbraco.library:NiceUrl($pageId1)}"><xsl:value-of select="string(umbraco.library:GetXmlNodeById($pageId1)/data [@alias = 'heading'])"/>a><br /> <xsl:value-of select="umbraco.library:FormatDateTime(umbraco.library:GetXmlNodeById($pageId1)/./data[@alias='datepublished'],'dd MMMM yyyy')"/>
</p>
I've also tried this:
<img src="{umbraco.library:GetMedia($pageId1)/data [@alias = 'newsImage']}" class="floatleft" width="60" height="45" />
but it said that "System.Xml.Xsl.XslTransformException: Extension object 'urn:umbraco.library' does not contain a matching 'GetMedia' method that has 1 parameter(s). "
Any help would be much appreciated as my poor brain hurts.
Thanks,
Tom
is working on a reply...