Search In
Hi all!
I am working on my new website ware I want to create a "playlist". The playlist should contain 7 urls for some mp3 files. The first and the last url is always the same, the middle 5 should be gathered from the top-five newest nodes that are childes to id=1103.
Exsample of the final output:
/media/mp3/intro.mp3 , /media/mp3/file01.mp3 , /media/mp3/file02.mp3 , /media/mp3/file03.mp3 , /media/mp3/file04.mp3 , /media/mp3/file05.mp3 , /media/mp3/final.mp3
After the list string i collected I will put it in to an audio player on the page.
Hi Webspas,
Is node Id "1103" a content or media node?
Either way, a simple XSLT macro can produce the output you need. Let us know the node type and we'll show you an example.
Cheers, Lee.
I'd think something like this would be a good start:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="umb" > <xsl:output method="text" indent="no" omit-xml-declaration="yes" /> <xsl:param name="currentPage" /> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:variable name="mediaRoot" select="$siteRoot//*[@id = 1103]" /> <xsl:variable name="firstFile" select="'/media/mp3/intro.mp3'" /> <xsl:variable name="lastFile" select="'/media/mp3/final.mp3'" /> <xsl:variable name="middleCount" select="5" /> <xsl:template match="/"> <xsl:variable name="mediaTopNode" select="umbraco.library:GetMedia($mediaRoot, true())]" /> <xsl:value-of select="$firstFile" /> <xsl:text>, </xsl:text> <xsl:for-each select="$mediaTopNode/*[umbracoExtension = 'mp3']"> <xsl:sort select="@createDate" data-type="text" order="descending" /> <xsl:if test="position() <= $middleCount"> <xsl:value-of select="umbracoFile" /> </xsl:if> <xsl:text>, </xsl:text> </xsl:for-each> <xsl:value-of select="$lastFile" /> </xsl:template> </xsl:stylesheet>
/Chriztian
#Lee: Deal! :-)
"1103" is a page node.
By the way: I would like to use the list string somewhere else inside the same XSLT file.
Chriztian beat me to it! ;-) (XSLT legend!)
He - thought about asking that too, Lee - should have, I can see :-)
@Webspas: So is the file an "Upload" datatype, or a Media Picker?
I've updated the code above, in case you might have used it as a starting point.
(There was a couple of "hurry-up, must. beat. Lee. post. now!" errors in the first draft :-)
Well, first I upload the file to Umbraco. Then I make a page for the file with additional information and pick the file. On another page I want to present the five newest files.
Does that answer your question?
Hi again,
Here's something that actually "works on my machine":
You'll have to replace the names in the first few lines (bolded for your convenience) with the names of the actual Doctype and propertyName you're using
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE xsl:stylesheet [ <!ENTITY DocumentTypeAlias "Mp3File"> <!ENTITY mediaPickerAlias "mediaFile"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="umbraco.library" > <xsl:output method="text" indent="no" omit-xml-declaration="yes" /> <xsl:param name="currentPage" /> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" /> <xsl:variable name="mediaRoot" select="$siteRoot//*[@id = 1103]" /> <xsl:variable name="firstFile" select="'/media/mp3/intro.mp3'" /> <xsl:variable name="lastFile" select="'/media/mp3/final.mp3'" /> <xsl:variable name="middleCount" select="5" /> <xsl:template match="/"> <xsl:value-of select="$firstFile" /> <xsl:text>, </xsl:text> <xsl:for-each select="$mediaRoot/&DocumentTypeAlias;"> <xsl:sort select="@createDate" data-type="text" order="descending" /> <xsl:if test="position() <= $middleCount"> <xsl:apply-templates select="&mediaPickerAlias;" /> <xsl:text>, </xsl:text> </xsl:if> </xsl:for-each> <xsl:value-of select="$lastFile" /> </xsl:template> <xsl:template match="&mediaPickerAlias;"> <xsl:variable name="mediaNode" select="umbraco.library:GetMedia(., false())" /> <xsl:value-of select="$mediaNode/umbracoFile" /> </xsl:template> </xsl:stylesheet>
Thank you very much! So far so good.
Now there is only one thing left, and as far I see it there are 2 possibilities:
The list that is created must be placed inside a Javascript in order to be played for the user. Can it be done by...
... or...
Or is there something else? I appreciate your replies!
You can just wrap a variable instruction around the template body to create the result as a string for reuse later on, e.g.:
<xsl:template match="/"> <xsl:variable name="playListCSV"> <xsl:value-of select="$firstFile" /> <xsl:text>, </xsl:text> <xsl:for-each select="$mediaRoot/&DocumentTypeAlias;"> <xsl:sort select="@createDate" data-type="text" order="descending" /> <xsl:if test="position() <= $middleCount"> <xsl:apply-templates select="&mediaPickerAlias;" /> <xsl:text>, </xsl:text> </xsl:if> </xsl:for-each> <xsl:value-of select="$lastFile" /> </xsl:variable> <!-- Lots of XSLT going on... --> <script type="text/javascript"> var playlist = "<xsl:value-of select="$playListCSV" />"; // Lots of JS processing... alert(playListCSV); </script> </xsl:template>
Also, change the output instruction and ask for CDATA output of script elements:
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" cdata-section-elements="script" />