Copied to clipboard

Flag this post as spam?

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


  • Aaron 1 post 21 karma points
    Aug 15, 2013 @ 23:26
    Aaron
    0

    Display all lowest level document nodes

    Hi,

    I have a really simple node tree that is organized in year and month folders.

    News
     -2013
      -08
       -Article 1
       -Article 2

    I want to be able to go to domain.com/news.aspx?altTemplate=RSS

    For which I have an RSS macro inserted into the template variation with an XSLT file that is supposed to descend and display all descendants of the current node. It only display the immediate descendents and I can't get what I want. Which is tho have all the articles displayed and not the folders.

    My code is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <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:rssdatehelper="urn:rssdatehelper"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        exclude-result-prefixes="msxml umbraco.library">


        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

        <!-- Update these variables to modify the feed -->
        <xsl:variable name="siteURL"          select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))"/>
        <xsl:variable name="rssNoItems"       select="/macro/rssNoItems"/>    
        <xsl:variable name="rssTitle"         select="/macro/rssTitle"/>
        <xsl:variable name="rssDescription"   select="/macro/rssDescription"/>

        

        <!-- This gets all news and events and orders by updateDate to use for the pubDate in RSS feed -->
        <xsl:variable name="pubDate">
          <xsl:for-each select="$currentPage//*[@isDoc]">
                <xsl:sort select="@createDate" data-type="text" order="descending" />
                <xsl:if test="position() = 1">
                    <xsl:value-of select="@updateDate" />
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>

        <xsl:template match="/">
            <!-- change the mimetype for the current page to xml -->
            <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
            
            <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
            <rss version="2.0"
                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/">

                <channel>
                    <title>
                        <xsl:value-of select="$rssTitle"/>
                    </title>
                    <link>
                        <xsl:value-of select="$siteURL"/>
                    </link>
                    <pubDate>
                        <xsl:value-of select="$pubDate"/>
                    </pubDate>
                    <generator>umbraco</generator>
                    <description>
                        <xsl:value-of select="$rssDescription"/>
                    </description>
                    <language>en</language>

                    <xsl:apply-templates select="$currentPage//*[@isDoc]">
                        <xsl:sort select="@createDate" order="descending" />
                    </xsl:apply-templates>
                </channel>
            </rss>

        </xsl:template>

        <xsl:template match="node">
           
                <item>
                    <title>
                        <xsl:value-of select="@nodeName"/>
                    </title>
                    <link>
                        <xsl:value-of select="$siteURL"/>
                        <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
                    </link>
                    <pubDate>
                        <xsl:value-of select="umbraco.library:FormatDateTime(@createDate,'r')" />
                    </pubDate>
                    <guid>
                        <xsl:value-of select="$siteURL"/>
                        <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
                    </guid>
                    <content:encoded>
                        <xsl:value-of select="concat('&lt;![CDATA[ ', current()/bodyText,']]&gt;')" disable-output-escaping="yes"/>
                    </content:encoded>
                </item>
          
        </xsl:template>

    </xsl:stylesheet>

    Any help on this would be so much appreciated.

    Thanks.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 16, 2013 @ 08:12
    Chriztian Steinmeier
    0

    Hi Aaron,

    Your code is a mix between the old "Legacy Schema" and the new default XML Schema - It looks as if you're using the new schema, so you need to change the match="node" template to this: <xsl:template match="*[@isDoc]">. Then you change the apply-templates instruction to only select the Article nodes - e.g., if the alias of those is Article, you'd do this:

    <xsl:apply-templates select="$currentPage//Article">
        <xsl:sort select="@createDate" order="descending" />
    </xsl:apply-templates>
    

    - That way, you specifically ask for every Article node below $currentPage.

    Hope this helps,

    /Chriztian

  • Jason 86 posts 156 karma points
    May 30, 2014 @ 13:09
    Jason
    0

    Hi Chriztian,

    Would you be able to help me with my RSS feed?  My problem is that I am trying to display the full content of the news articles, not just the titles.

    My XSLT code is as follows....please let me know if you need more info.  Thank you in advance!!  -Jason

    http://www.saintleo.edu/news-events/news/rssFeed

     

    <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:dc="http://purl.org/dc/elements/1.1/"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        exclude-result-prefixes="msxml umbraco.library">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>
     
      <xsl:param name="documentTypeAlias" select="translate(/macro/documentTypeAlias, ' ', '')"/>
        <xsl:param name="title" select="/macro/title"/>
     
      <!-- The name of the document property that holds the content -->
      <xsl:variable name="propertyName">
        <xsl:choose>
          <xsl:when test="string(/macro/propertyName) != ''">
            <xsl:value-of select="/macro/propertyName"/>
          </xsl:when>
          <xsl:otherwise>
            bodyText
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
     
      <!-- How deep it should recurse -->
      <xsl:variable name="depth">
        <xsl:choose>
          <xsl:when test="string(/macro/depth) != ''">
            <xsl:value-of select="/macro/depth"/>
          </xsl:when>
          <xsl:otherwise>
            1
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

        <!-- Variables to pull in from node -->
        <xsl:variable name="SiteURL" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))"/>
      <xsl:variable name="numberOfItems">
        <xsl:choose>
          <xsl:when test="$currentPage/rssNumberOfItems!=''">
            <xsl:value-of select="$currentPage/rssNumberOfItems"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>99</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable> 
        <xsl:variable name="pubDate">
        <xsl:choose>
          <xsl:when test="string($documentTypeAlias) != ''">
            <xsl:for-each select="$currentPage/*[@isDoc and name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
              <xsl:sort select="@createDate" data-type="text" order="descending" />
              <xsl:if test="position() = 1">
                <xsl:value-of select="umbraco.library:FormatDateTime(./@createDate, 'r')" />
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide) != '1']">
              <xsl:sort select="@createDate" data-type="text" order="descending" />
              <xsl:if test="position() = 1">
                <xsl:value-of select="umbraco.library:FormatDateTime(./@createDate, 'r')" />
              </xsl:if>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
        </xsl:variable>

        <xsl:template match="/">
            <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</xsl:text>
            <rss version="2.0"
                xmlns:atom="http://www.w3.org/2005/Atom"
                xmlns:content="http://purl.org/rss/1.0/modules/content/"
                xmlns:dc="http://purl.org/dc/elements/1.1/">
                    <channel>
              <title>
                <xsl:choose>
                  <xsl:when test="string($currentPage/rssTitle) != ''">
                    <xsl:value-of select="$currentPage/rssTitle"/>
                  </xsl:when>
                  <xsl:when test="string($title) != ''">
                    <xsl:value-of select="$title"/>
                  </xsl:when>
                  <xsl:otherwise>
                                    <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')"/><xsl:text> RSS Feed</xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
              </title>
              <link>
                <xsl:value-of select="$SiteURL"/>
              </link>
              <pubDate>
                <xsl:value-of select="$pubDate"/>
              </pubDate>
              <generator>EyeCatch RSS Generator</generator>
              <description>
                <xsl:choose>
                  <xsl:when test="$currentPage/rssDescription!=''">
                    <xsl:value-of select="$currentPage/rssDescription"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:text>No description available for this feed</xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
              </description>
              <xsl:if test="$currentPage/rssLanguage!=''">
                <language>
                  <xsl:value-of select="$currentPage/rssLanguage"/>
                </language>
              </xsl:if>

                        <atom:link href="{concat('http://', umbraco.library:RequestServerVariables('HTTP_HOST'), umbraco.library:RequestServerVariables('URL'))}" rel="self" type="application/rss+xml" />
                       
              <xsl:choose>
                <xsl:when test="string($documentTypeAlias) != ''">
                  <xsl:for-each select="$currentPage/*[@isDoc and name() = $documentTypeAlias and string(umbracoNaviHide)!='1']">
                    <xsl:sort select="@createDate" data-type="text" order="descending" />
                    <xsl:if test="position() &lt;= $numberOfItems">
                      <xsl:call-template name="subNode">
                        <xsl:with-param name="node" select="."/>
                        <xsl:with-param name="currentdepth" select="0"/>
                      </xsl:call-template>
                    </xsl:if>
                  </xsl:for-each>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:for-each select="$currentPage/*[@isDoc and string(umbracoNaviHide)!='1']">
                    <xsl:sort select="@createDate" data-type="text" order="descending" />
                    <xsl:if test="position() &lt;= $numberOfItems">
                      <xsl:call-template name="subNode">
                        <xsl:with-param name="node" select="."/>
                        <xsl:with-param name="currentdepth" select="0"/>
                      </xsl:call-template>
                    </xsl:if>
                  </xsl:for-each>
                </xsl:otherwise>
              </xsl:choose>
                </channel>
            </rss>
        </xsl:template>

        <xsl:template name="subNode">
            <xsl:param name="node"/>
        <xsl:param name="currentdepth"/>
       
        <xsl:if test="$currentdepth &lt; $depth">
          <item>
            <title>
              <xsl:value-of select="$node/@nodeName"/>
            </title>
            <link>
              <xsl:value-of select="umbraco.library:NiceUrlFullPath($node/@id)"/>
            </link>
            <pubDate>
              <xsl:value-of select="umbraco.library:FormatDateTime($node/@createDate, 'r')"/>
            </pubDate>
            <dc:creator>
              <xsl:value-of select="@writerName"/>
            </dc:creator>
            <xsl:if test="string($node/Tags)!=''">
              <xsl:for-each select="umbraco.library:Split($node/Tags, ',')/value">
                <xsl:sort data-type="text" order="ascending"/>
                <category>
                  <xsl:value-of select="current()"/>
                </category>              
              </xsl:for-each>
            </xsl:if>
            <guid>
              <xsl:value-of select="umbraco.library:NiceUrlFullPath($node/@id)"/>
            </guid>
            <description>
              <xsl:value-of select="$node/*[name() = $propertyName]"/>
            </description>
            <content:encoded>
              <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
              <xsl:value-of select="$node/*[name() = $propertyName]" disable-output-escaping="yes"/>
              <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
            </content:encoded>
          </item> 
         
          <!-- Recursive action -->
          <xsl:if test="($currentdepth + 1) &lt; $depth">
            <xsl:choose>
              <xsl:when test="string($documentTypeAlias) != ''">
                <xsl:for-each select="$node/*[@isDoc and name() = $documentTypeAlias and string(umbracoNaviHide)!='1']">
                  <xsl:sort select="@createDate" data-type="text" order="descending" />
                  <xsl:if test="position() &lt;= $numberOfItems">
                    <xsl:call-template name="subNode">
                      <xsl:with-param name="node" select="."/>
                      <xsl:with-param name="currentdepth" select="$currentdepth + 1"/>
                    </xsl:call-template>
                  </xsl:if>
                </xsl:for-each>
              </xsl:when>
              <xsl:otherwise>
                <xsl:for-each select="$node/*[@isDoc and string(umbracoNaviHide)!='1']">
                  <xsl:sort select="@createDate" data-type="text" order="descending" />
                  <xsl:if test="position() &lt;= $numberOfItems">
                    <xsl:call-template name="subNode">
                      <xsl:with-param name="node" select="."/>
                      <xsl:with-param name="currentdepth" select="$currentdepth + 1"/>
                    </xsl:call-template>
                  </xsl:if>
                </xsl:for-each>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
        </xsl:if>
        </xsl:template>
    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft