Copied to clipboard

Flag this post as spam?

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


  • Daniel Dawson 27 posts 47 karma points
    Sep 05, 2011 @ 15:31
    Daniel Dawson
    0

    RSS Problem - CDATA still showing HTML tags

    Hi there,

    My RSS feed for showing blog posts is working fine except it is still showing the HTML tags such as <p>, <ul> and <li> etc. I don't understand what's going wrong. This is what it looks like in the description tag of the RSS Feed -

    <description>
    <![CDATA[ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed hendrerit consectetur lacus, vitae varius felis auctor eget. Sed fermentum ultrices quam, quis auctor orci vestibulum sed. Proin rutrum porttitor dolor et gravida. Cras pharetra pretium aliquam. Curabitur pharetra tortor ut mauris aliquam vel semper neque dictum. Mauris vitae ultricies est. Cras consequat, lacus non tristique eleifend, velit ante tempor urna, eget pellentesque sem mauris ac nulla. Nullam non lectus ultrices mi consequat laoreet ac quis justo. Etiam a nibh felis, non placerat nibh. Vivamus magna metus, ullamcorper eget euismod at, vestibulum ut arcu. Praesent massa neque, laoreet eget faucibus in, molestie vitae justo. Maecenas quis felis ante, id hendrerit nibh.</p> ]]>
    </description>
    This is the XSLT so far:

    <?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/"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:BlogLibrary="urn:BlogLibrary"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltStrings BlogLibrary">


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

      <xsl:param name="currentPage"/>

      <xsl:variable name="iscommentfeed" select="//macro/iscommentfeed" />

      <!-- Update these variables to modify the feed -->
      <xsl:variable name="RSSNoItems" select="string('10')"/>
      <xsl:variable name="RSSTitle">
        <xsl:value-of select="$currentPage/ancestor-or-self::Blog/blogName"/>
        <xsl:if test="$iscommentfeed = '1'">
          <xsl:textcomment feed</xsl:text>
          <xsl:if test="$currentPage [name() = 'BlogPost']">
            <xsl:value-of select="concat(' for ', $currentPage/@nodeName)"/>
          </xsl:if>
        </xsl:if>
        <xsl:if test="string-length(umbraco.library:Request('tag')) &gt; 0">
          <xsl:value-of select="concat(' for tag ', umbraco.library:Request('tag'))"/>
        </xsl:if>
      </xsl:variable>
      <xsl:variable name="SiteURL" select="concat('http://',string(umbraco.library:RequestServerVariables('HTTP_HOST')))"/>
      <xsl:variable name="RSSDescription" select="$currentPage/ancestor-or-self::Blog/blogDescription"/>

      <!-- This gets all news and events and orders by updateDate to use for the pubDate in RSS feed -->
      <xsl:variable name="pubDate">
        <xsl:choose>
          <xsl:when test="$iscommentfeed = '1'">
            <xsl:for-each select="$currentPage//BlogPostComment">
              <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:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="string-length(umbraco.library:Request('tag')) &gt; 0">
                <xsl:for-each select="$currentPage//BlogPost [contains(Exslt.ExsltStrings:lowercase(./tags), Exslt.ExsltStrings:lowercase(umbraco.library:Request('tag')))]">
                  <xsl:sort select="PostDate" data-type="text" order="descending" />
                  <xsl:if test="position() = 1">
                    <xsl:value-of select="@updateDate" />
                  </xsl:if>
                </xsl:for-each>
              </xsl:when>
              <xsl:otherwise>
                <xsl:for-each select="$currentPage//BlogPost">
                  <xsl:sort select="PostDate" data-type="text" order="descending" />
                  <xsl:if test="position() = 1">
                    <xsl:value-of select="@updateDate" />
                  </xsl:if>
                </xsl:for-each>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </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:choose>
              <xsl:when test="$iscommentfeed = '1'">

                <xsl:choose>
                  <xsl:when test="$currentPage [name() = 'BlogPost']">
                    <xsl:apply-templates select="BlogLibrary:GetCommentsForPost($currentPage/@id)//comment">
                      <xsl:sort select="@created" order="descending" />
                    </xsl:apply-templates>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:apply-templates select="BlogLibrary:GetCommentsForBlog($currentPage/ancestor-or-self::Blog/@id)//comment">
                      <xsl:sort select="@created" order="descending" />
                    </xsl:apply-templates>
                  </xsl:otherwise>
                </xsl:choose>


              </xsl:when>
              <xsl:otherwise>

                <xsl:choose>
                  <xsl:when test="string-length(umbraco.library:Request('tag')) &gt; 0">
                    <xsl:apply-templates select="$currentPage//BlogPost [contains(Exslt.ExsltStrings:lowercase(./tags), Exslt.ExsltStrings:lowercase(umbraco.library:Request('tag')))]">
                      <xsl:sort select="PostDate" order="descending" />
                    </xsl:apply-templates>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:apply-templates select="$currentPage//BlogPost">
                      <xsl:sort select="PostDate" order="descending" />
                    </xsl:apply-templates>
                  </xsl:otherwise>
                </xsl:choose>

              </xsl:otherwise>
            </xsl:choose>

          </channel>
        </rss>

      </xsl:template>

      <xsl:template match="BlogPost">
        <xsl:if test="position() &lt;= $RSSNoItems">
          <xsl:variable name="link">
            <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
          </xsl:variable>

          <xsl:variable name="content">
            <xsl:value-of select="bodyText"/>
          </xsl:variable>
          <item>
            <title>
              <xsl:value-of select="@nodeName"/>
            </title>
            <link>
              <xsl:value-of select="$SiteURL"/>
              <xsl:value-of select="$link"/>
            </link>
            <pubDate>
              <xsl:value-of select="umbraco.library:FormatDateTime(PostDate,'r')" />
            </pubDate>
            <guid>
              <xsl:value-of select="$SiteURL"/>
              <xsl:value-of select="$link"/>
            </guid>
            <description>
              <xsl:value-of select="concat('&lt;![CDATA[ ',$content,']]&gt;')"/>
            </description>
          </item>
        </xsl:if>
      </xsl:template>

    </xsl:stylesheet>

     

    Any help would be much appreciated as I really don't know where I'm going wrong.

    Thanks,

    Daniel

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 06, 2011 @ 20:55
    Lee Kelleher
    0

    Hi Daniel,

    If you want to have the contents of the <description> tags wrapped with CDATA, then you'll need to add the following attribute to the <xsl:output>:

    <xsl:output method="xml" omit-xml-declaration="yes" cdata-section-elements="description" />

    Thenk you can output the 'bodyText' value like so... (I don't see a need to store the value in the $content variable)

    <description>
        <xsl:value-of select="bodyText"/>
    </description>

    Cheers, Lee.

  • Daniel Dawson 27 posts 47 karma points
    Sep 07, 2011 @ 17:58
    Daniel Dawson
    0

    Thanks a lot Lee that worked!

    I didn't know thats what I needed to add to the <xsl:output> so you've tought me something new today!

    Cheers, Daniel

Please Sign in or register to post replies

Write your reply to:

Draft