Thanks for your reply. I'd been experimenting with that, but haven't yet got it to work. This is what I've tried in the for-each statement based on what was in that article -
I can't quite work out how to get the ID from it (as you can tell, I'm very new to XSLT). I'd like to set the mediaFolderId variable as the node ID of the folder.
I think you have to set the "deep" property in the function to 1 (with is true) since you then get not only the media node from the selected ID, then you get the media node from the selected ID and all his subnodes.
But you have to know in which xml schema you are working. If you are in the old xml schema it would be:
When I save the XSLT file, I get the error messages-
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 (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Root(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)
Ah, the old "Value was either too large or too small for an Int32" on save error.
It's because there is no current page when you save the XSLT, so the GetMedia() call is not being passed a valid integer. You can either simply ignore errors on save and it should work in your actual site, or check that you have a valid media ID before calling GetMedia()
Getting media folder ID from Content Picker
I currently have an XSLT gallery macro which displays the image in a media folder of a particular ID.
<xsl:variable name="mediaFolderId" select="number(1066)" />
I am trying to work out how to change that XSLT to get the ID of the selected folder in a media picker named galleryFolder.
I've been experimenting with it, but I can't get it to work. Could somebody please tell me what it needs to be?
Thanks a lot.
You have to use the GetMedia function of the umbraco.library:
http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia
hth, Thomas
Thanks for your reply. I'd been experimenting with that, but haven't yet got it to work. This is what I've tried in the for-each statement based on what was in that article -
<xsl:for-each select="umbraco.library:GetMedia($currentPage/data[@alias='galleryFolder'], 0)/Image">
<xsl:for-each select="umbraco.library:GetMedia($currentPage/galleryFolder, 0)/Image">
I can't quite work out how to get the ID from it (as you can tell, I'm very new to XSLT). I'd like to set the mediaFolderId variable as the node ID of the folder.
The original for-each statement is -
<xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/Image">
I think you have to set the "deep" property in the function to 1 (with is true) since you then get not only the media node from the selected ID, then you get the media node from the selected ID and all his subnodes.
But you have to know in which xml schema you are working. If you are in the old xml schema it would be:
<xsl:for-each select="umbraco.library:GetMedia($currentPage/data [@alias='galleryFolder'], 'true')/node [@nodeTypeAlias = 'image']'">
in the new schema it would be:
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($currentPage/galleryFolder, 'true')/Image"/>
Also check the aliase of the media types
hth, Thomas
I'm using Umbraco 4.7
OK, I'm now trying this -
EDIT - I've now pasted in the whole XSLT file.
xsl:stylesheet [ ]>
<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="mediaFolderId" select="number(1102)" />
<xsl:variable name="thumbWidth" select="number(84)" />
<xsl:variable name="thumbHeight" select="number(84)" />
<xsl:template match="/">
<xsl:if test="number($mediaFolderId)">
<div class="photos maingallery">
<ul id="gallery">
<xsl:for-each select="umbraco.library:GetMedia($currentPage/galleryFolder, 'true')/Image">
<xsl:if test="umbracoFile !=''">
<li>
<a href="{umbracoFile}" title="{@nodeName}" rel="gallery">
<img src="/imageGen.ashx?image={umbraco.library:UrlEncode(umbracoFile)}&width={$thumbWidth}&height={$thumbHeight}" width="{$thumbWidth}" height="{$thumbHeight}" alt="{@nodeName}" title="{@nodeName}" class="thumbnail" />
a>
li>
xsl:if>
xsl:for-each>
ul>
div>
xsl:if>
xsl:template>
xsl:stylesheet>
When I save the XSLT file, I get the error messages-
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 (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at Root(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)
Ah, the old "Value was either too large or too small for an Int32" on save error.
It's because there is no current page when you save the XSLT, so the GetMedia() call is not being passed a valid integer. You can either simply ignore errors on save and it should work in your actual site, or check that you have a valid media ID before calling GetMedia()
If you want to do the test, change your for-each line to the following block of code:
As far as I'm aware there isn't a less long winded way of doing this.
That's great, thanks!
is working on a reply...