Copied to clipboard

Flag this post as spam?

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


  • Shannon 148 posts 171 karma points
    Jan 26, 2011 @ 21:07
    Shannon
    0

    Get a list of blog entries with a postdate within the last 24 hours

    Anyone know how to format a XSL so that I get a list of blog entries with a postdate within the last 24 hours? I tried using a combo of currentdate and <= but couldn't get it right.

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

    Hi Shannon

    Could you provide us with the example you have tried to use?

    If I remember correctly you need to turn the currentdate and the dates to compare with into numbers. So for instance todays date would be 201101260000 - And then you should be able to compare the other dates using the same number format.

    /Jan

  • Ralph van Vugt 57 posts 101 karma points
    Jan 26, 2011 @ 22:11
    Ralph van Vugt
    0

    Hi Shannon,

    Few weeks ago I had the same problem.

    Check http://our.umbraco.org/forum/developers/xslt/15697-Hide-nodes-which-haven't-been-updated

    Here's the XSLT

    <xsl:param name="currentPage"/>
       
       
    <xsl:variable name="currentDate" select="umbraco.library:CurrentDate()"/>
       
    <xsl:variable name="updated" select="$currentPage/@updateDate"/>
       
    <xsl:variable name="difference" select="Exslt.ExsltDatesAndTimes:seconds(Exslt.ExsltDatesAndTimes:difference(umbraco.library:FormatDateTime($updated, 'yyyy-MM-dd') , Exslt.ExsltDatesAndTimes:date())) div 86400"/>
       
    <xsl:template match="/">
     
       
    <xsl:choose>
         
    <xsl:when test="$difference &gt;= 1">
            show'm
         
    </xsl:when>
         
    <xsl:otherwise>
            hide'm
         
    </xsl:otherwise>
       
    </xsl:choose>

    </xsl:template>

    </xsl:stylesheet>

    Maybe it will help you.

  • Shannon 148 posts 171 karma points
    Jan 26, 2011 @ 22:25
    Shannon
    0

    So this should work:

      <xsl:param name="currentPage"/>
        <xsl:variable name="currentDate" select="umbraco.library:CurrentDate()"/>
        <xsl:variable name="updated" select="$currentPage/@postDate"/>
        <xsl:variable name="difference" select="Exslt.ExsltDatesAndTimes:seconds(Exslt.ExsltDatesAndTimes:difference(umbraco.library:FormatDateTime($updated,
    'yyyy-MM-dd') , Exslt.ExsltDatesAndTimes:date())) div 86400"
    />
       
      <xsl:template match="/">
        <div id="slider" class="news_banner" >
          <xsl:for-each select="$currentPage/ancestor-or-self::*//BlogPost [@isDoc and position() &lt; 6 and $difference &lt;=3]">
            <xsl:sort select="pageViewCount" order="descending" />
            <xsl:if test="blogImage != ''">
              <xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
              <xsl:if test="$crop/@url != ''">
                <a href="{umbraco.library:NiceUrl(@id)}"><img src="{$crop/@url}" alt="{@nodeName}" title="#htmlcaption{@id}"  /></a>
              </xsl:if>
            </xsl:if>
          </xsl:for-each>
        </div>
        <xsl:for-each select="$currentPage/ancestor-or-self::*//BlogPost [@isDoc and position() &lt; 6]">
          <xsl:if test="blogImage != ''">
            <xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
            <xsl:if test="$crop/@url != ''">
              <div id="htmlcaption{@id}" class="nivo-html-caption"><xsl:value-of select="@nodeName" /> - <a href="{umbraco.library:NiceUrl(@id)}">Read more...</a></div>
            </xsl:if>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>

    This should work in retreving blog posts but I am missing something

  • Ralph van Vugt 57 posts 101 karma points
    Jan 27, 2011 @ 01:09
    Ralph van Vugt
    0

    Hi Shannon,

    Try something like this:

     

    <xsl:for-each select="$currentPage/ancestor-or-self::*//BlogPost [@isDoc]">
       <xsl:sort select="pageViewCount" order="descending" />
       <xsl:if test="blogImage != '' and position() < 6 and $difference <=3">
          <xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
          <xsl:if test="$crop/@url != ''">
          <a href="{umbraco.library:NiceUrl(@id)}"><img src="{$crop/@url}" alt="{@nodeName}" title="#htmlcaption{@id}"  />a>
        xsl:if>
    xsl:if>
    xsl:for-each>

    If this doesn't work you can set the variables $update and $difference after the sort command.

     

  • Shannon 148 posts 171 karma points
    Feb 01, 2011 @ 23:10
    Shannon
    0

    I figured out something different.

     

    <?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.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:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:UCommentLibrary="urn:UCommentLibrary" xmlns:uForum="urn:uForum" xmlns:uForum.raw="urn:uForum.raw"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary UCommentLibrary uForum uForum.raw ">
      <xsl:output method="xml" omit-xml-declaration="yes"/>
      <xsl:param name="currentPage"/>
        <xsl:variable name="blognode" select="umbraco.library:GetXmlNodeById(1187)" />
        <xsl:variable name="today" select="umbraco.library:CurrentDate()" />
        <xsl:variable name="later" select="umbraco.library:DateAdd($today, 'd', -20)" /> //20 Days before date today.
        <xsl:variable name="count" select="4" />

       
      <xsl:template match="/">
        <div id="slider" class="news_banner" >
          <xsl:for-each select="$blognode/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later) ]">
            <xsl:sort select="pageViewCount" data-type="number" order="descending" />
            <xsl:if test="blogImage != ''">
              <xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
              <xsl:if test="$crop/@url != '' and position() &lt;= $count" >
                <a href="{umbraco.library:NiceUrl(@id)}"><img src="{$crop/@url}" alt="{@nodeName}" title="#htmlcaption{@id}"  /></a>
              </xsl:if>
            </xsl:if>
          </xsl:for-each>
        </div>
        <xsl:for-each select="$blognode/ancestor-or-self::*//BlogPost [@isDoc and umbraco.library:DateGreaterThanOrEqual(PostDate, $later) ]">
          <xsl:sort select="pageViewCount" data-type="number" order="descending" />
          <xsl:if test="blogImage != ''" >
            <xsl:variable name="crop" select="umbraco.library:GetMedia(blogImage, 0)/crops/crops/crop [@name='NewsBanner']" />
            <xsl:if test="$crop/@url != '' and position() &lt;= $count">
              <div id="htmlcaption{@id}" class="nivo-html-caption"><xsl:value-of select="@nodeName" /> - <a href="{umbraco.library:NiceUrl(@id)}">Read more...</a></div>
            </xsl:if>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>
    </xsl:stylesheet>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies