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.)
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?
<!-- 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>
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
Hi Max,
Check this out - should be fairly self-explanatory - otherwise, just ask what's going on...
(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
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
This is the code I am working on at the mo:
Eddy
Thank you all it was very useful
is working on a reply...