Edit online

Dynamically Generating an RSS Feed

3 Feb 2022
Read time: 5 minute(s)

When publishing a website from DITA XML content, we can dynamically generate an RSS XML feed by customizing the WebHelp Responsive output.

DITA WebHelp output can be customized using a publishing template mechanism. Inside a publishing template folder, there is an opt file that can contain links to various XSLT stylesheets that are useful for customizations. For example, we'll add a link to a stylesheet for processing such special keyword label elements:
            <extension file="xslt/createRSS.xsl" id="com.oxygenxml.webhelp.xsl.createNavLinks"/>
The createRSS.xsl stylesheet generates an rss.xml file that contains references to all topics referenced in the DITA Map:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    <xsl:param name="JSON_OUTPUT_DIR_URI"/>
    <xsl:template match="/toc:toc">
        <xsl:apply-templates mode="rss" select="."/>
    <xsl:template match="/toc:toc" mode="rss">
        <xsl:result-document href="{concat($JSON_OUTPUT_DIR_URI, '/../../../../rss.xml')}" indent="yes">
            <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
                    <title>TITLE OF RSS FEED HERE</title>
                    <description>DESCRIPTION OF FEED HERE</description>
                    <atom:link href="https://my.website/rss.xml" rel="self" type="application/rss+xml" xmlns:atom="http://www.w3.org/2005/Atom"/>
                    <lastBuildDate><xsl:value-of select="format-dateTime(current-dateTime(),'[F], [D] [M01] [Y] [h] [P] [z]')"/></lastBuildDate>
                    <generator>FEED GENERATOR NAME</generator>
                    <managingEditor>EDITOR EMAIL INFORMATION</managingEditor>
                    <webMaster>WEBMASTER EMAIL INFORMATION</webMaster>
                    <copyright>Copyright Info Here. All rights reserved.</copyright>
                        <title>BLOG TITLE HERE
                    <xsl:for-each select="//toc:topic">
                        <xsl:if test="not(@href = 'javascript:void(0)')">
                                <title><xsl:value-of select="toc:title"/></title>
                                <link><xsl:value-of select="concat('/', @href)"/></link>   
                                <guid isPermaLink="false"><xsl:value-of select="@href"/></guid>
                                <xsl:variable name="ref" select="replace(resolve-uri(@href, base-uri()), '\.html', '.dita')"/>
                                <xsl:variable name="date" select="document($ref)/*/prolog/critdates/created/@date"/>
                                    <xsl:when test="$date">
                                        <pubDate><xsl:value-of select="
                                            '[F], [D01] [MNn,*-3] [Y] 00:00:00 GMT')"/></pubDate>
                                        <!-- Format like: Thu, 20 Dec 2022 02:46:11 UTC -->
                                        <!-- Set some fixed date so that the topic does not appear as new -->
                                        <pubDate> Wed, 1 Jan 2020 02:46:11 GMT</pubDate>
The published output will produce an RSS feed similar to the one here: https://blog.oxygenxml.com/rss.xml. For each topic referenced in the feed, a publication date is computed based on its creation date specified in the prolog:
<topic id="rss_feed_generation">
            <created date="YYYY-MM-DD"/>

The WebHelp publishing template used for publishing this blog already has a customization to create the RSS feed: https://github.com/oxygenxml/blog/tree/master/publishing/webhelpBlogTemplate.

Using the RSS Feed With Follow.it to Receive New Posts by Email

Websites such as Follow.it allow you to register a link to your RSS feed and produce a small HTML form that can be embedded in your blog. Users who register to receive notifications when new posts are available in the RSS feed will receive automatic emails.

Once the RSS feed is available on the website, the following steps can be followed to integrate with Follow.it:
  1. Go to the Follow.it website and add a reference to your RSS feed.
  2. On the website, customize the form that will be embedded in your blog HTML contents.
  3. In the the opt file (inside the Oxygen WebHelp publishing template folder), add references to an XML file that contains the structure for it to appear after the content of each article:
    <fragment file="html-fragments/subscribe.xml" placeholder="webhelp.fragment.after.toc_or_tiles"/>
    <fragment file="html-fragments/subscribe.xml" placeholder="webhelp.fragment.after.feedback"/>
  4. Create the subscribe.xml file and paste the form HTML content created by Follow.it inside it. Make the HTML content well-formed.