Began work in news2rss-template

This commit is contained in:
Martin Byrenheid 2014-03-23 01:58:13 +01:00
parent 5484446574
commit 993793018e
4 changed files with 203 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:atom="http://www.w3.org/2005/Atom"
exclude-result-prefixes="xsl date">
<xsl:output method="xml"
version="1.0"
encoding="utf-8"
indent="yes"/>
<xsl:include href="news2rss.xsl" />
<xsl:param name="archivefeed"/>
<xsl:template name="main">
<channel>
<title>www.c3d2.de Newsfeed</title>
<link>http://www.c3d2.de/</link>
<description>Neues aus dem Chaos Computer Club Dresden</description>
<language>de-de</language>
<image>
<title>Chaosknoten</title>
<url><xsl:value-of select="$baseurl"/>images/ck.png</url>
<link>http://www.c3d2.de/</link>
</image>
<xsl:if test="$archivefeed">
<atom:link rel="prev-archive" href="{$archivefeed}"/>
</xsl:if>
<!-- Insert the actual rss entries, provided by
news2rss-template -->
<xsl:call-template name="rss_entries">
<xsl:with-param name="prefix" select="$prefix" />
</xsl:call-template>
</channel>
</xsl:template>
</xsl:stylesheet>

31
doc/README.md Normal file
View File

@ -0,0 +1,31 @@
General concept:
- (TBD) Structure of XML-files is predefined by the
DTDs in the dtd-folder, which contains all the entities
supported by the framework.
- Basic transformations offered by framework
-> offer general-purpose transformations
-> located in transformation
- Domain-specific XSL-Templates (e.g. html.xsl, rss.xsl)
-> should normally only include a template with name "main", which contains
the basic domain-specific structure for the created objects of this type
-> located in content/<mydomain>/templates
-> definition of own templates is possible, but may cause name collisions with
the imported templates provided by the framework
-> each template may include the appropriate transformation template
from the framework and use the provided templates
Process for final formats (such as html or rss):
1. Transformation initiated by calling "xsltproc $PATHS {html,rss}.xsl <mydocument>.xml
2. Framework-included template matches root element, may do some preparations (as in news2rss.xsl)
and call the "main"-template.
3. The "main"-template defines the common structure and calls the needed templates
provided by the framework at the needed places.
Changelog to master (besides new architecture):
news2rss:
- Transformation of <item>:
-> removed insertion of <author> and <category> to make code more generic
-> <author> may in future be taken directly from the @author-attribute in the xml-file

View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:atom="http://www.w3.org/2005/Atom"
exclude-result-prefixes="xsl date">
<xsl:output method="xml"
version="1.0"
encoding="utf-8"
indent="yes"/>
<!--
# Starting point
# ==============
#
# Matches root and calls the
# main-Template defined within the
# application-specific template.
-->
<xsl:template match="news">
<xsl:element name="rss">
<xsl:attribute name="version">2.0</xsl:attribute>
<!--xsl:attribute name="xml:lang">de</xsl:attribute-->
<!-- include domain-specific channel description -->
<xsl:call-template name="main" />
</xsl:element>
</xsl:template>
<!--
# Interface templates
# ===================
#
# To be used by the application-specific
# xsl-template.
-->
<xsl:template name="rss_entries">
<xsl:param name="prefix" />
<!-- TODO: Insert "now": <pubDate><xsl:value-of select="news/item/@date"/></pubDate> -->
<xsl:for-each select="newsfile">
<xsl:sort select="date:seconds(document(.)/item/@date)" data-type="number" order="descending" />
<xsl:variable name="newsfile" select="."/>
<xsl:if test="(position() &lt;= $maxitems) and
starts-with(substring-after(substring-after($newsfile, '/'), '/'), $prefix)">
<xsl:apply-templates select="document(.)/item">
<xsl:with-param name="newsfile" select="$newsfile"/>
</xsl:apply-templates>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!--
# Additional templates
# ====================
#
-->
<!--
# Template to transform an item into an rss-entry.
-->
<xsl:template match="item">
<xsl:param name="newsfile"/>
<item>
<xsl:variable name="href">
<xsl:value-of select="$baseurl"/>
<xsl:value-of select="substring-before(substring-after($newsfile, 'content/'), '.xml')"/>
<xsl:text>.html</xsl:text>
</xsl:variable>
<title><xsl:value-of select="@title"/></title>
<description>
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<div xmlns="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="document($newsfile)/item/*"/>
</div>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</description>
<link><xsl:value-of select="$href"/></link>
<!--
TODO:
Jemand mit iTunes (erhältlich für OSX und Windows)
muss mal die itunes-extensions einbauen:
http://www.apple.com/itunes/podcasts/techspecs.html
-->
<xsl:for-each select=".//*[name() = 'resource' or name() = 'alternative']">
<xsl:variable name="resource_href">
<xsl:call-template name="make-href">
<xsl:with-param name="href" select="@url"/>
</xsl:call-template>
</xsl:variable>
<enclosure url="{$resource_href}"
length="{@size}"
type="{@type}" />
</xsl:for-each>
<guid isPermaLink="true"><xsl:value-of select="$href"/></guid>
<pubDate>
<xsl:call-template name="date-to-rfc822">
<xsl:with-param name="date" select="@date"/>
</xsl:call-template>
</pubDate>
<content:encoded>
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<div xmlns="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="document($newsfile)/item/*"/>
</div>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</content:encoded>
<xsl:variable name="flattr_link">
<xsl:call-template name="make-flattr-link">
<xsl:with-param name="newsfile" select="$newsfile"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="string-length($flattr_link) &gt; 0">
<atom:link rel="payment" href="{$flattr_link}" type="text/html"/>
</xsl:if>
<xsl:copy-of select="resource/sc:chapters"
xmlns:sc="http://podlove.de/simple-chapters"/>
</item>
</xsl:template>
</xsl:stylesheet>