Copied to clipboard

Flag this post as spam?

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


  • kentiler 76 posts 69 karma points
    Mar 06, 2010 @ 19:03
    kentiler
    0

    Sort By Day Of Week?

    Hi,

    I have a datepicker property on a set of pages.  I would like to be able to list them on a page under each day of week that they apply to.  For example:

    Does someone have a snippet that I could use for this logic?

    Monday

    Page 1
    Page 2
    Page 3

    Tuesday

    Page 4
    Page 5
    Page 6

    Wednesday

    Page 7
    Page 8
    Page 9

    Thursday

    ...

    Thanks!

    --Kent

  • Jesper Hauge 298 posts 487 karma points c-trib
    Mar 06, 2010 @ 20:23
    Jesper Hauge
    2

    The Umbraco xslt files includes the Exslt libraries, so you could try something along these lines. (This haven't been tested, so there might be some syntactical errors). This is assuming the pages you're trying to list is subpages to the current page, one or more levels below.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
        <!ENTITY nbsp "&#x00A0;">
    ]>
    <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.Exslt.ExsltDatesAndTimes="urn:Exslt.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.Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    
        <xsl:output method="xml" omit-xml-declaration="yes"/>
    
        <xsl:param name="currentPage"/>
    
        <xsl:template match="/">
            <dl>
                <dt>Monday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '2']" />
                </dd>
                <dt>Tuesday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '3']" />
                </dd>
                <dt>Wednesday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '4']" />
                </dd>
                <dt>Thursday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '5']" />
                </dd>
                <dt>Friday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '6']" />
                </dd>
                <dt>Saturday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '7']" />
                </dd>
                <dt>Sunday</dt>
                <dd>
                    <xsl:apply-templates select="$currentPage/descendant::node[Exslt.ExsltDatesAndTimes:dayinweek(./data[@alias='myDate']) = '1']" />
                </dd>
            <dl>
        </xsl:template>
    
        <xsl:template match="node">
            <p>
                <xsl:value-of select="@nodeName" />
            </p>
        </xsl:template>
    
    </xsl:stylesheet>

    Regards
    Jesper Hauge

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 06, 2010 @ 21:43
    Chriztian Steinmeier
    0

    Hi Kent,

    Here's my take, using what I like to call a "Helper Variable" - a chunk of custom XML that's used as kind of a proxy for the actual transformation:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:date="urn:Exslt.ExsltDatesAndTimes"
        exclude-result-prefixes="umb date msxml"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <!-- Create an XML helper variable -->
        <xsl:variable name="weekdays">
            <day name="Monday" id="2" />
            <day name="Tueday" id="3" />
            <day name="Wednesday" id="4" />
            <day name="Thursday" id="5" />
            <day name="Friday" id="6" />
            <day name="Saturday" id="7" />
            <day name="Sunday" id="1" />
        </xsl:variable>
    
        <xsl:template match="/">
            <xsl:apply-templates select="msxml:node-set($weekdays)/day" />
        </xsl:template>
    
        <!-- Actual output for each page -->
        <xsl:template match="node">
            <li>
                <xsl:value-of select="@nodeName" />
            </li>
        </xsl:template>
    
        <!-- Template for a <day> element in the $weekdays variable -->
        <xsl:template match="day">
            <xsl:variable name="days" select="$currentPage/node[date:dayinweek(data[@alias = 'dateProperty']) = current()/@id]" />
            <h2><xsl:value-of select="@name" /></h2>
    
            <xsl:if test="$days">
                <ul>
                    <xsl:apply-templates select="$days" />
                </ul>
            </xsl:if>
        </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • kentiler 76 posts 69 karma points
    Mar 07, 2010 @ 05:05
    kentiler
    0

    Thanks for the responses Jesper and Chriztian!  I chose Chriztian's first and it worked great. 

    --Kent

     

Please Sign in or register to post replies

Write your reply to:

Draft