laminas-feed
laminas-feed copied to clipboard
Feature Request: Add XSLT support
It would be nice to style generated feeds with a xsl:stylesheet. See the XSLT entry on Wikipedia for more general information about this.
I was thinking about adding a header to reference the stylesheet, e.g.
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="podcast.xsl"?>
taken from an ORF podcast feed.
Originally posted by @podcasthosting at https://github.com/zendframework/zend-feed/issues/107
An XSLT transformation is usually best applied to the XML feed directly, and not through a third party component or language. XSLT is Turing complete, and also a very good FP language, so I'd suggest digging that way first (by piping the XML directly through CLI XML tools).
Originally posted by @Ocramius at https://github.com/zendframework/zend-feed/issues/107#issuecomment-508796131
@Ocramius If I understand you correctly than what you are suggesting is not what I want to achieve. I want to make a RSS feed look good in the browser. It should be the feed generated through zend-feed itself without piping it through any extra tools.
Originally posted by @podcasthosting at https://github.com/zendframework/zend-feed/issues/107#issuecomment-508803541
I'd rather say that you take the RSS feed (input or output) and pass it to XSLT directly: XSLT is good and mature, use it :+1:
Originally posted by @Ocramius at https://github.com/zendframework/zend-feed/issues/107#issuecomment-508828919
taken from an ORF podcast feed.
Example: https://files.orf.at/podcast/oe1/oe1_imoe1journalzugast.xml
@podcasthosting Please try the following example: (based on "Writer: Getting Started")
// Create feed
$feed = new Laminas\Feed\Writer\Feed;
$feed->setTitle("Paddy's Blog");
$feed->setDescription("Paddy's Blog");
$feed->setLink('http://www.example.com');
// Create entry
$entry = $feed->createEntry();
$entry->setTitle('All Your Base Are Belong To Us');
$entry->setLink('http://www.example.com/all-your-base-are-belong-to-us');
$entry->addAuthor([
'name' => 'Paddy',
'email' => '[email protected]',
'uri' => 'http://www.example.com',
]);
$entry->setDateModified(time());
$entry->setDateCreated(time());
$entry->setDescription('Exposing the difficulty of porting games to English.');
$entry->setContent(
'I am not writing the article. The example is long enough as is ;).'
);
$feed->addEntry($entry);
// Render feed (creates DOMDocument object)
$writer = new Laminas\Feed\Writer\Renderer\Feed\Rss($feed);
$writer->render();
// Add processing instruction
$writer->getElement()->parentNode->insertBefore(
$writer->getDomDocument()->createProcessingInstruction(
'xml-stylesheet',
'title="Demo" type="text/xsl" href="https://files.orf.at/podcast/oe1/podcast.xsl"'
),
$writer->getElement()
);
// Ouput XML
echo $writer->saveXml();
Ouput:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet title="Demo" type="text/xsl" href="https://files.orf.at/podcast/oe1/podcast.xsl"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<channel>
<title>Paddy's Blog</title>
<description>Paddy's Blog</description>
<generator>Laminas_Feed_Writer 2 (https://getlaminas.org)</generator>
<link>http://www.example.com</link>
<item>
<title>All Your Base Are Belong To Us</title>
<description><![CDATA[Exposing the difficulty of porting games to English.]]></description>
<pubDate>Thu, 24 Sep 2020 06:43:50 +0000</pubDate>
<link>http://www.example.com/all-your-base-are-belong-to-us</link>
<guid>http://www.example.com/all-your-base-are-belong-to-us</guid>
<author>[email protected] (Paddy)</author>
<dc:creator>Paddy</dc:creator>
<content:encoded><![CDATA[I am not writing the article. The example is long enough as is ;).]]></content:encoded>
<slash:comments>0</slash:comments>
</item>
</channel>
</rss>