Copied to clipboard

Flag this post as spam?

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


  • Wilson 5 posts 25 karma points
    Nov 23, 2011 @ 17:31
    Wilson
    0

    Want to output RSS feeds for past 30 days only please help!

    I have been struggling with what most of you might think is very simple.

    I am trying to output the rss feeds only for the past month however have had no luck so far please find below my code so far. (I cant output all the rss feeds but just want to filter and show only th past months). Any help is much appreciated. I do know the "" does not make sense there but thats the whole point i am lost :-(


      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:rssdatehelper="urn:rssdatehelper"
      xmlns:dc="http://purl.org/dc/elements/1.1/"
      xmlns:content="http://purl.org/rss/1.0/modules/content/"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
      xmlns:Exslt.ExsltDatesAndTimes="urn: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"
      xmlns:umbraco.contour="urn:umbraco.contour"
      xmlns:uQR="urn:uQR"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour uQR ">


     

     

     
     
     
     

     
     
       
         
         
           
         
       
     

     
       
     
     
     
       
       
        <?xml version="1.0" encoding="UTF-8"?>
            xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/">
         
            <br />          <xsl:value-of select="$RSSTitle"/><br />       
           
             
           
           
             
           
           
             
           
            umbraco
           
            en
           
             
           
         
       
     

     
       
       
          <br />        <xsl:value-of select="@nodeName"/><br />     
         
           
           
         
         
             
         
         
             
               
             
         
         
           
           
         
         
           
         
       
       
     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 23, 2011 @ 20:14
    Jan Skovgaard
    0

    Hi Wilson

    I've deleted the other post for you and I've removed the "(previous...)" part of the title for this one.

    Must admit that I have not looked very deeply on the above code - but one thing that springs to my eye is that you're trying to manipulate text strings and not numbers. If you make a <xsl:value-of select="$todaysDate" /> it will return a value like this 2011-11-23T19:56:27 and so does @createDate.

    So in order to be able to substract the two dates you need to do the following

    1) Get rid of the time information

    2) Get rid of "-" so you have a number like 20111123

    This can be done by using substring-before() and translate(), which are native XSLT functions. The way we're using the Translate() function is also referred to as a "poor man's replace" (Thank's to Chriztian Steinmeier for teaching that waaay back).

    So in your last template I would make two variables, one called now and one called createDate like shown below.

    <xsl:variable name="now" select="translate(substring-before($todaysDate,'T'),'-','')">
    <xsl:variable name="createDate" select="translate(substring-before(@createDate,'T'),'-','')">

    The substring-before() makes sure you only get the date without the time and the translate removes the "-".

    Now you can make a substraction by doing this number($now)-number($createDate) &gt; number(30).

    You could also make specify that the content of the variable should be a number by adding it like this
    <xsl:variable name="now" select="number(translate(substring-before($todaysDate,'T')),'-','')" />.

    I hope the above makes sense and helps :)

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 23, 2011 @ 20:16
    Jan Skovgaard
    0

    Oops! Note to self, don't edit the title of posts...apparently it messes up the content of it...#h5is...

    If the above post does not solve your issue, please post the code in the reply once again. Our has some bugs that means it's not currently possible for you to edit posts yourself.

    /Jan

  • Wilson 5 posts 25 karma points
    Nov 24, 2011 @ 11:31
    Wilson
    0

    Hi Jan,

    Thank you for your response and your time I am working on this at the moment and will post a reponse as soon as I get this this working.

  • Wilson 5 posts 25 karma points
    Nov 24, 2011 @ 17:33
    Wilson
    0

    Hi Jan,

    I was finally able to get it working using the following extension method.

    As date calculations turned out to be more complicated than just date1 - date 2 (yeah i know :P)

    Pasting the code below for extension method and how i used it in apply templates for any one who has questions post here and I would be happy to help.

    xmlns:wilson="http://wilson.co.uk/"

     

    <xsl:apply-templates select="$currentPage/ancestor-or-self::*[@level=1]//* [@isDoc and string(umbracoNaviHide) != '1' and wilson:isOnlyAMonthOld(@createDate)]">
              <xsl:sort select="@createDate" order="descending" />
    </xsl:apply-templates>

    <msxsl:script implements-prefix="wilson"  language="C#">
        <![CDATA[
           
            public bool isOnlyAMonthOld(string dateString)
            {   
                DateTime updateDate;
                const string format = "s";

                DateTime now = DateTime.Now;
                DateTime aMonthAgoDate = now.AddMonths(-2);
                updateDate = DateTime.ParseExact(dateString, format, null);

                if (updateDate >= aMonthAgoDate)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
               
            ]]>
      </msxsl:script>

     


             


               
            public bool isOnlyAMonthOld(string dateString)
            {   
                DateTime updateDate;
                const string format = "s";

                DateTime now = DateTime.Now;
                DateTime aMonthAgoDate = now.AddMonths(-2);
                updateDate = DateTime.ParseExact(dateString, format, null);

                if (updateDate >= aMonthAgoDate)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
               
            ]]>
     

             


               
            public bool isOnlyAMonthOld(string dateString)
            {   
                DateTime updateDate;
                const string format = "s";

                DateTime now = DateTime.Now;
                DateTime aMonthAgoDate = now.AddMonths(-2);
                updateDate = DateTime.ParseExact(dateString, format, null);

                if (updateDate >= aMonthAgoDate)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
               
            ]]>
     

  • Wilson 5 posts 25 karma points
    Nov 24, 2011 @ 17:37
    Wilson
    0

    Just a note:  the method "isOnlyAMonthOld" pasted twice is just becuase i tried to edit my own.

    @Jan another bug mate :-(

Please Sign in or register to post replies

Write your reply to:

Draft