I have the following xslt which was created when i made a new xslt file and chose the rss feed template. How could i modify this to get title/description/etc from child nodes of a parent i can specify? ie node 1155
Also can i modify it so instead of pubdate, i can have it display the display date which is a field in the document? We sometimes post-date articles...
<!-- Update these variables to modify the feed --> <xsl:variable name="RSSNoItems" select="string('10')"/> <xsl:variable name="RSSTitle" select="string('CentraComm RSS')"/> <xsl:variable name="SiteURL" select="string('http://www.centracomm.net')"/> <xsl:variable name="RSSDescription" select="string('this is a news feed')"/>
<!-- 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/node"> <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')"/>
<!-- Update these variables to modify the feed --> <xsl:variable name="startNode" select="/macro/startNode" /> <xsl:variable name="RSSNoItems" select="string('10')"/> <xsl:variable name="RSSTitle" select="string('my website')"/> <xsl:variable name="SiteURL" select="string('http://www.my url.net')"/> <xsl:variable name="RSSDescription" select="string('my description')"/> <xsl:variablename="startNode"select="/macro/startNode"/>
<!-- 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="umbraco.library:GetXmlNodeById($startNode)/node"> <xsl:sort select="@createDate" data-type="text" order="ascending" /> <xsl:if test="position() = 1"> <xsl:value-of select="./data [@alias='date']" /> </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')"/>
RSS Feed from child nodes of specific parent.
I have the following xslt which was created when i made a new xslt file and chose the rss feed template. How could i modify this to get title/description/etc from child nodes of a parent i can specify? ie node 1155
Also can i modify it so instead of pubdate, i can have it display the display date which is a field in the document? We sometimes post-date articles...
Thanks for your help!
<?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: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"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<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('CentraComm RSS')"/>
<xsl:variable name="SiteURL" select="string('http://www.centracomm.net')"/>
<xsl:variable name="RSSDescription" select="string('this is a news feed')"/>
<!-- 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/node">
<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"><?xml version="1.0" encoding="UTF-8"?></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/node [string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="@createDate" order="descending" />
</xsl:apply-templates>
</channel>
</rss>
</xsl:template>
<xsl:template match="node">
<xsl:if test="position() <= $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('<![CDATA[ ', ./data [@alias='bodyText'],']]>')" disable-output-escaping="yes"/>
</content:encoded>
</item>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Hi Amir
To choose a parent node, youd need to pass in a macro paramater using the content picker control.
E.g. paramater alias of "startNode", then when you insert the macro you can select start node (e.g 1155)
Then add something like this
Then change the line that goes
to something like (ps $currentPage will need to be changed to
umbraco.library:GetXmlNodeById($startNode)
wherever it appears)
<xsl:apply-templates select="umbraco.library:GetXmlNodeById($startNode)/node [string(data [@alias='umbracoNaviHide']) != '1']">
To change the descriptions etc just find the relevant line in the xslt and replace it with your own page fields, e.g.
becomes
etc.
To change the pubdate, you need to change the variable "pubdate" so that it grabs the date that you've set in the backend, from something like
to
(note, this still sorts by createDate)
All code it untested, and meant as a starting point, not a complete solution! Good luck.
Dan
Dan, thank you so much for this. This is overall working great, but I'm still struggling with a couple of issues.
1. I still can't get the date to show in the feed
2. How do i make it so the main content area is truncated after a bit instead of showing the whole story?
Here's the code as i've modified it.
Thank you,
Amir
is working on a reply...