Copied to clipboard

Flag this post as spam?

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


  • Iulia Maria Jensen 40 posts 71 karma points
    May 26, 2014 @ 11:22
    Iulia Maria Jensen
    0

    Calendar function

    Hi,

    I have to make a calendar that starts with the current month and shows next 12 (so may 2014 - april 2015).

    It has to, of course, be dynamic.

    Do you have any suggestions as to how I can do this with XSLT?

     

    Kind regards,

    Iulia

  • Mads Jørgensen 74 posts 226 karma points
    May 26, 2014 @ 11:36
    Mads Jørgensen
    0

    I would kinda do the magic with ordinary number calculation.

    <xsl:variable name="currentMonth" select="umbraco.library:FormatDateTime(umbraco.library:CurrentDate(), 'M')" />
    
    <xsl:call-template name="doStuff">
      <xsl:with-param name="month" select="$currentMonth" />
      <xsl:with-param name="counter" select="1" />
    </xsl:call-template>
    ---
    <xsl:template name="doStuff">
      <xsl:if test="$currentMonth == 12">call january</xsl:if>
      <xsl:if test="$counter &lt;= 12">call stuff</xsl:if>
    </xsl:template>
    

    Makes sence?

  • Iulia Maria Jensen 40 posts 71 karma points
    May 26, 2014 @ 11:44
    Iulia Maria Jensen
    0

    Hi Mads,

    Thanks for your input! I was thinking that maybe there are some functions out there I didn't know about which would or could make my life easier o:3.

    That's similar to what I had myself.  

    But it's more like it starts with current so:

    05-2014,06-2014,07-2014,08-2014,09-2014,10-2014,11-2014,12-2014,   (CHANGE) 01-2015,02-2015,03-2015... (12 months)

    It means that I need a var for the year which should increment when month is 12 and of course, the one for month. So I need some sort of looping mechanism with these two variables.

    Then I need to extract the name of the month based on the month counter.

    Roughly.. Hoped there was an easier way though.. 

    /Iulia

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 26, 2014 @ 11:45
    Chriztian Steinmeier
    100

    Hi Iulia,

    Depending on what you need to do with the calendar, you may get a few things "for free" by having a look at the Calendar Helper I have on GitHub... You definitely want to make sure that you calculate using real date functions (i.e. not "just" adding 30 days, etc.) if you're at any point going to do stuff on the actual dates.

    /Chriztian

  • Mads Jørgensen 74 posts 226 karma points
    May 26, 2014 @ 11:51
    Mads Jørgensen
    0

    As Chriztian says... Have a look at the Calendar Helper! It sorta rocks.

    Otherwise you could do all your math in a classic for.loop hack!

    <xml version="1.0" encoding="utf-16"?> 
    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
        <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes" /> 
        <xsl:template match="/Items"> 
    
            <xsl:call-template name="forloop"> 
                <xsl:with-param name="i">1<xsl:with-param> 
                <xsl:with-param name="count">3<xsl:with-param> 
            <xsl:call-template> 
    
        <xsl:template> 
    
        <xsl:template name="forloop"> 
            <xsl:param name="i" /> 
            <xsl:param name="count" /> 
    
            <xsl:if test="$i <= $count"> 
    
                <xsl:variable name="name" select="format-number($i,'Item_0')"/> 
                <xsl:variable name="price" select="format-number($i,'Item_0_Price')"/> 
    
                <xsl:value-of select="Item[@Name=$name]"/>: $<xsl:value-of select="Item[@Name=$price]"/> 
                <br/> 
    
            <xsl:if> 
    
    
            <xsl:if test="$i <= $count"> 
                <xsl:call-template name="forloop"> 
                    <xsl:with-param name="i"> 
                        <xsl:value-of select="$i + 1"/> 
                    <xsl:with-param> 
                    <xsl:with-param name="count"> 
                        <xsl:value-of select="$count"/> 
                    <xsl:with-param> 
                <xsl:call-template> 
            <xsl:if> 
    
        <xsl:template> 
    <xsl:stylesheet> 
    

    The last if statement sorta is where you should do your magic. Pass any variable into the forloop you'd want!

  • Iulia Maria Jensen 40 posts 71 karma points
    May 26, 2014 @ 11:53
    Iulia Maria Jensen
    1

    Awesome! Thanks guys! If I could, I would set you both for "solved" :)

Please Sign in or register to post replies

Write your reply to:

Draft