Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kasper Dyrvig 246 posts 379 karma points
    Aug 31, 2010 @ 08:14
    Kasper Dyrvig
    0

    Generate comma separated list of nodepropertys

    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.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 31, 2010 @ 10:25
    Lee Kelleher
    0

    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.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 31, 2010 @ 10:29
    Chriztian Steinmeier
    1

    Hi Webspas,

    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() &lt;= $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

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 31, 2010 @ 10:31
    Kasper Dyrvig
    0

    #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.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 31, 2010 @ 10:35
    Lee Kelleher
    0

    Chriztian beat me to it! ;-) (XSLT legend!)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 31, 2010 @ 10:38
    Chriztian Steinmeier
    0

    He - thought about asking that too, Lee - should have, I can see :-)

    @Webspas: So is the file an "Upload" datatype, or a Media Picker? 

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 31, 2010 @ 11:27
    Chriztian Steinmeier
    0

    Hi Webspas,

    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 :-)

    /Chriztian 

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 31, 2010 @ 11:37
    Kasper Dyrvig
    0

    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?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 31, 2010 @ 14:19
    Chriztian Steinmeier
    1

    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() &lt;= $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>

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 31, 2010 @ 19:57
    Kasper Dyrvig
    0

    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...

    • placing the output from the list-XSLT in the macro parameters for the player-XSLT (in the template)?

    ... or...

    • parsing the final list string further down in the same XSLT and create the player there?

    Or is there something else? I appreciate your replies!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 31, 2010 @ 20:44
    Chriztian Steinmeier
    2

    Hi Webspas,

    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() &lt;= $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" />

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Aug 31, 2010 @ 21:03
    Kasper Dyrvig
    0

    Wuhoo! It's working!

    I had never figured that solution out myself. Great thanks!

    PS: The final work of this website will soon be released at www.thenoise.dk :-)

Please Sign in or register to post replies

Write your reply to:

Draft