I am looking at creating an XSLT/Macro control to display all the media within the media folder(inc PDF's, images, video etc) I have seen a few post around and tried some of them and can't seem to get anything to work, not sure if the properties have changed from the posts I am looking at or my lack of XSLT skills, but does anyone have something I can start with. I understand that a media picker would need to be used also.
Thanks very much for your very quick response. I cant seem to get this working, the if statement <xsl:iftest="normalize-space($mediaFolder)"> I'm not sure what it is meant to do, but it doesn't go in to this, which then doesn't go in to the Folder template. Is there something I am meant to do here? I created the MediaFolder parameter:
That test makes sure that there's something selected in the parameter before trying to call the GetMedia() extension (otherwise we'll get a nasty .NET exception).
On the template where you insert the macro - were you asked to select a Media folder? You should get something like this after adding the Macro to the template:
Oh blimey - I keep forgetting this - it's because the mediaCurrent only gives you the empty <Folder> XML - so the normalize-space() will not grab anything.
If you control everything you can leave it off, but otherwise you can change it to this, to make sure you're not trying to run the extension if no folder has been selected:
<xsl:if test="$mediaFolder[Folder]">
Which means "If the mediaFolder variable has a Folder element in it" ...
When I add the code you kindly supplied I get an error message when saving the XSLT:
Error occured
System.Xml.Xsl.XslLoadException: 'xsl:sort' cannot be a child of the 'xsl:if' element. An error occurred at D:\home\site\wwwroot\xslt\635412779284722600_temp.xslt(21,5).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
That is where I started! But unfortunately the sort there creates a similar error message:
Error occured
System.Xml.Xsl.XslLoadException: 'xsl:sort' cannot be a child of the 'ul' element. An error occurred at D:\home\site\wwwroot\xslt\635412793527439859_temp.xslt(33,9). at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
That is where I started! But unfortunately the sort there creates a similar error message:
Error occured
System.Xml.Xsl.XslLoadException: 'xsl:sort' cannot be a child of the 'ul' element. An error occurred at D:\home\site\wwwroot\xslt\635412793527439859_temp.xslt(33,9). at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
The error message was different but still a show-stopper when saving the XSLT.
System.Xml.Xsl.XslLoadException: 'xsl:sort' cannot be a child of the 'li' element. An error occurred at D:\home\site\wwwroot\xslt\635415447778488841_temp.xslt(44,5).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Below is the code I am trying to add a sort function to, it works well without the XSLT sort code.
<?xml version="1.0" encoding="utf-8" ?>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<xsl:variable name="mediaFolder" select="/macro/mediaFolder" />
<xsl:template match="/">
<xsl:if test="$mediaFolder[Folder]">
<xsl:variable name="media" select="umb:GetMedia($mediaFolder/Folder/@id, true())" />
<!-- If no errors, this will run the Folder template below -->
<xsl:apply-templates select="$media[not(error)]" />
</xsl:if>
</xsl:template>
<!-- Template for the folder -->
<xsl:template match="Folder">
<ul>
<!-- Run templates for individual items (just add Media type aliases) -->
<xsl:apply-templates select="File | Image" />
</ul>
</xsl:template>
<!-- Template for items - you can create individual templates to render them differently -->
<xsl:template match="File | Image">
<li>
<a href="{umbracoFile}" target="_blank">
<xsl:value-of select="@nodeName" />
</a>
</li>
</xsl:template>
I can see why the errors you're getting can seem a little confusing at first, but the processor is really just trying to tell you that you've put the sort element in the wrong place...
You can use it directly inside a for-each or an apply-templates instruction - but usually, when using apply-templates, you're using the empty (i.e. self-closing) version, so you need to open that one to put the sort element inside, e.g. this:
<ul>
<!-- Run templates for individual items (just add Media type aliases) -->
<xsl:apply-templates select="File | Image" />
</ul>
...becomes this:
<ul>
<!-- Run templates for individual items (just add Media type aliases) -->
<xsl:apply-templates select="File | Image">
<xsl:sort select="@nodeName" />
</xsl:apply-templates>
</ul>
List all media files, umbraco 4.7
Hi all,
I am looking at creating an XSLT/Macro control to display all the media within the media folder(inc PDF's, images, video etc) I have seen a few post around and tried some of them and can't seem to get anything to work, not sure if the properties have changed from the posts I am looking at or my lack of XSLT skills, but does anyone have something I can start with. I understand that a media picker would need to be used also.
Any ideas?
Thanks
Jason
Hi Jason,
This should get you started - you just need to add a mediaFolder parameter on the macro of type "mediaCurrent"...
/Chriztian
Hi Chriztian
Thanks very much for your very quick response. I cant seem to get this working, the if statement <xsl:iftest="normalize-space($mediaFolder)"> I'm not sure what it is meant to do, but it doesn't go in to this, which then doesn't go in to the Folder template. Is there something I am meant to do here?
I created the MediaFolder parameter:
Thanks again for your help.
Jason
Chriztian, if I take out the normalize space I get it to work, seems that it somehow didnt like that. Thats a great starting point for me.
Thank you again for your quick response.
Jason
Hi Jason,
That test makes sure that there's something selected in the parameter before trying to call the GetMedia() extension (otherwise we'll get a nasty .NET exception).
On the template where you insert the macro - were you asked to select a Media folder? You should get something like this after adding the Macro to the template:
/Chriztian
Oh blimey - I keep forgetting this - it's because the mediaCurrent only gives you the empty <Folder> XML - so the normalize-space() will not grab anything.
If you control everything you can leave it off, but otherwise you can change it to this, to make sure you're not trying to run the extension if no folder has been selected:
Which means "If the mediaFolder variable has a Folder element in it" ...
/Chriztian
Hi there,
This is exactly what I needed to display a list of PDF files in a sub folder of the media library on my Umbraco site. Thanks!
My XSLT knowledge is pretty scant, but I'd like to be able to sort the results of the macro by the media item title.
Attempts to use xsl:sort (which I have used with xsl:for-each in the past) within the template block fails.
Any pointers to ordering the list of media items by the Name property would be highly appreciated.
Best wishes
Ben
Hi Ben
I assume that you are using the code from Chriztian's post. If not could you please copy your code in here, it's easier to help then.
But if you are using Chriztian's code, I think that you should be able to do something like that.
Hope this helps,
/Dennis
Thanks for the swift reply Dennis.
Yes, the code is Chriztian's and works great!
When I add the code you kindly supplied I get an error message when saving the XSLT:
Hi Ben,
Okay,
What if you are do the sort in here instead:
Hope this helps,
/Dennis
Hi Dennis,
That is where I started! But unfortunately the sort there creates a similar error message:
Error occured
System.Xml.Xsl.XslLoadException: 'xsl:sort' cannot be a child of the 'ul' element. An error occurred at D:\home\site\wwwroot\xslt\635412793527439859_temp.xslt(33,9).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Thanks
Ben
Hi Dennis,
That is where I started! But unfortunately the sort there creates a similar error message:
Error occured
System.Xml.Xsl.XslLoadException: 'xsl:sort' cannot be a child of the 'ul' element. An error occurred at D:\home\site\wwwroot\xslt\635412793527439859_temp.xslt(33,9).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Thanks
Ben
Hi Ben,
Okay, have you tried to do the sort inside the li like this:
Hope this works :-)
/Dennis
Hi Dennis,
Yes I tried in there too.
The error message was different but still a show-stopper when saving the XSLT.
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Below is the code I am trying to add a sort function to, it works well without the XSLT sort code.
Any pointers really welcome!
Many thanks, Ben
Hi Ben,
I can see why the errors you're getting can seem a little confusing at first, but the processor is really just trying to tell you that you've put the sort element in the wrong place...
You can use it directly inside a for-each or an apply-templates instruction - but usually, when using apply-templates, you're using the empty (i.e. self-closing) version, so you need to open that one to put the sort element inside, e.g. this:
...becomes this:
Hope that helps! :)
/Chriztian
is working on a reply...