Copied to clipboard

Flag this post as spam?

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


  • Mohamed Besher El Said 39 posts 258 karma points
    Sep 17, 2014 @ 17:02
    Mohamed Besher  El Said
    0

    Rss Feed using Xslt

    I want to generate xslt for News and put this output in another RssNews page not in News Page

    this content of News and its items 

    i used this code in Xslt files Create> Choose a snippet:Rss Feed  but its only Work in News page .this code in xslt file

     

    <?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: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:variable name="currentSiteRoot" select="$currentPage/ancestor-or-self::* [@isDoc][@level=1]" />

     

      <xsl:variable name="urlPrefix">

        <xsl:text>http://</xsl:text>;

        <xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" />

      </xsl:variable>

     

      <!-- Update these variables to modify the feed -->

      <xsl:variable name="rssNoItems" select="string('20')"/>

      <xsl:variable name="rssTitle" select="$currentSiteRoot/@nodeName"/>

      <xsl:variable name="siteUrl" select="$urlPrefix"/>

      <xsl:variable name="rssDescription" select="$currentSiteRoot/metadescription"/>

     

      <!-- 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="$currentSiteRoot//* [@isDoc]">

          <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: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:atom="http://www.w3.org/2005/Atom">

          <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>

     

            <atom:link rel="self" type="application/rss+xml">

              <xsl:attribute name="href">

                <xsl:value-of select="$urlPrefix" />

                <xsl:text>/rss.aspx</xsl:text>

              </xsl:attribute>

            </atom:link>

     

            <xsl:apply-templates select="$currentPage/ancestor-or-self::*[@level = 1]//NewItem">

              <xsl:sort select="@createDate" order="descending" />

            </xsl:apply-templates>

     

          </channel>

        </rss>

     

      </xsl:template>

     

      <xsl:template match="* [@isDoc]">

        <xsl:if test="position() &lt;= $rssNoItems">

     

          <item>

            <title>

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

            </title>

            <author>

              <xsl:text>[email protected]</xsl:text>

            </author>

            <link>

              <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="umbraco.library:NiceUrl(@id)"/>

            </guid>

     

            <xsl:call-template name="content">

              <xsl:with-param name="useText" select="concat('&lt;![CDATA[ ', umbraco.library:Replace(./newbody, '/media/', concat($siteUrl, '/media/')),']]&gt;')"/>

            </xsl:call-template>

     

          </item>

        </xsl:if>

      </xsl:template>

     

      <xsl:template name="content">

        <xsl:param name="useText" />

        <description>

          <xsl:value-of select="$useText" disable-output-escaping="yes"/>

        </description>

        <content:encoded>

          <xsl:value-of select="$useText" disable-output-escaping="yes"/>

        </content:encoded>

      </xsl:template>

     

    </xsl:stylesheet>

    When insert it into News Page .give me output below 

    when insert into page RssNews .Give me this output Below because it doesn't know news childern

    is there way to make it working in another Page ???



     

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Sep 17, 2014 @ 23:46
    Dennis Aaen
    0

    Hi Mohamed and welcome to Our.

    I will try to see if I can help you. As you said you´re using the code XSLT snippet for RSS Feed which is excellent. The way it works is by you are placing the Rss feed XSLT macro on a tempate and then apply the template to your url.

    So first you create your XSLT, with asscisuted macro, which I assume that you already have done. The next step is to create a temlpate http://our.umbraco.org/documentation/Using-Umbraco/Creating-Basic-Site/Creating-Your-First-Template-and-Content-Node or http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/templating/setting-up-our-first-template/ and place the RSS feed macro on it. You could called it RSS. 

    I have make a screenshot so you can see what I mean.


    And the way that you are access the RSS feed then is by adding /rss in the url of the page that you are viewing. So if you are on your frontpage, and want to access the RSS feed you simply visit this URL. http://www.yourdomain.com/rss then you will get pages in your RSS feed that, are children of the homepage. If you want your news in a RSS feed then the URL could look like: http://www.yourdomain.com/news/rss where the news page then will show news items in the RSS feed

    So the RSS fieed will show the children of the page that your viewing in the browser.

    The code snippet for the RSS Feed XSLT looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
      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:Examine="urn:Examine"
      exclude-result-prefixes="msxml umbraco.library Examine ">

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

      <xsl:param name="currentPage"/>

      <!-- Update these variables to modify the feed -->
      <xsl:variable name="RSSNoItems" select="string('10')"/>
      <xsl:variable name="RSSTitle" select="string('My sample rss')"/>
      <xsl:variable name="SiteURL" select="string('Add your url here')"/>
      <xsl:variable name="RSSDescription" select="string('Add your description here')"/>

      <!-- 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 and string(umbracoNaviHide) != '1']">
              <xsl:sort select="@createDate" order="descending" />
            </xsl:apply-templates>
          </channel>
        </rss>

      </xsl:template>

      <xsl:template match="* [@isDoc]">
        <xsl:if test="position() &lt;= $RSSNoItems">
          <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[ ', ./bodyText,']]&gt;')" disable-output-escaping="yes"/>
            </content:encoded>
          </item>
        </xsl:if>
      </xsl:template>

    </xsl:stylesheet>.

    Hope this helps, and make sense

    /Dennis

  • Mohamed Besher El Said 39 posts 258 karma points
    Sep 20, 2014 @ 10:33
    Mohamed Besher  El Said
    100

    thank Dennis Aaen  for your fast response 

    your response is very helpful for me .

    i want to tags <body of news > </body of news>  

    1. How to add another tags to me  xml ???

    2. How to view this rss xml in umbrco ??


Please Sign in or register to post replies

Write your reply to:

Draft