Copied to clipboard

Flag this post as spam?

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


  • Max 144 posts 166 karma points
    Mar 30, 2011 @ 09:38
    Max
    0

    XSLT filtering using Dates (Year only)

    I have a news list page macro which will be filters by parameter year for example 2011,2010,2009,

    when the paramter is 2011 it should filter all datas from the date according to the year selected

    any code examples wil be useful

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 30, 2011 @ 21:33
    Chriztian Steinmeier
    2

    Hi Max,

    Check this out - should be fairly self-explanatory - otherwise, just ask what's going on...

    <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />
    
    <!-- Input from somewhere... -->
    <xsl:variable name="years" select="'2011,2010,2008'" />
    
    <!-- Convert to nodes -->
    <xsl:variable name="years-as-nodes" select="umbraco.library:Split($years, ',')" />
    
    <!-- Process the year values -->
    <xsl:apply-templates select="$years-as-nodes/value" />
    
    <!-- Template for one year value -->
    <xsl:template match="value">
        <section>
            <h1><xsl:value-of select="." /></h1>
            <!-- Process all Documents created this year -->
            <xsl:apply-templates select="$root//*[starts-with(@createDate, .)]" />
        </section>
    </xsl:template>
    
    <!-- Template for each matching Document -->
    <xsl:template match="*[@isDoc]">
        <p>
            <xsl:value-of select="substring(@createDate, 1, 10)" />: <xsl:value-of select="@nodeName" />
        </p>
    </xsl:template>

    (If you know you only need to process one specific Document Type, substitute the name (alias) of that for the asterisks in the above code, to improve performance.)

    /Chriztian

  • eddy 43 posts 64 karma points
    Mar 31, 2011 @ 17:02
    eddy
    0

    Hi Chriztian

    I'd like to use this for a news archive page I've been putting off for a while but I don't understand what is happening in the last template. Could you shed any light on it?

    Thanks, Eddy

  • eddy 43 posts 64 karma points
    Mar 31, 2011 @ 17:11
    eddy
    0

     

    This is the code I am working on at the mo:

    <xsl:variable name="years" select="'2011,2010,2009'" />
    <xsl:variable name="nodeID" select="1061" />
    <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />
    <!-- Convert to nodes -->
    <xsl:variable name="years-as-nodes" select="umbraco.library:Split($years, ',')" />

      <!-- Process all the year nodes or values -->
        <xsl:template match="/">
          <xsl:apply-templates select="$years-as-nodes/value">
            <xsl:sort order="descending" />
          </xsl:apply-templates>
        </xsl:template>  
        
      <!-- Template for one year value -->
      <xsl:template match="value">
        <section>
          <h2>News from
            <xsl:value-of select="." />
          </h2>
          <!-- Process all Documents created this year -->
          <ul>
            <xsl:apply-templates select="$root//*[starts-with(@createDate, .)]" />
          </ul>
        </section>
      </xsl:template>
      
      <!-- Template for each matching Document -->
      <xsl:template match="*[@isDoc]">
        <li>
         <xsl:value-of select="substring(@createDate, 1, 10)" />:
            <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
          </a>
        </li>
      </xsl:template

    Eddy

     

  • Max 144 posts 166 karma points
    Apr 07, 2011 @ 08:13
    Max
    0

    Thank you all it was very useful

Please Sign in or register to post replies

Write your reply to:

Draft