Skip to content

Instantly share code, notes, and snippets.

@dmj
Last active July 3, 2016 11:43
Show Gist options
  • Save dmj/0e1414fd8a4ed0ecd87fbfb184998ea2 to your computer and use it in GitHub Desktop.
Save dmj/0e1414fd8a4ed0ecd87fbfb184998ea2 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Timestamp: <2016-07-03 13:41:08 dmaus>
#
/usr/bin/java -jar /usr/share/java/tagsoup.jar http://www.zeit.de/serie/fischer-im-recht > fischer.xhtml
E=$?
if [ $E -ne 0 ]; then
exit $E
fi
xsltproc -o fischer.atom fischer.xsl fischer.xhtml
E=$?
if [ $E -ne 0 ]; then
exit $E
fi
<?xml version="1.0" encoding="utf-8"?>
<!-- Transformation Startseite "Fischer im Recht" nach Atom -->
<!-- Author: David Maus <[email protected]> -->
<!-- Timestamp: <2016-07-02 11:52:37 dmaus> -->
<xsl:transform version="1.0"
exclude-result-prefixes="html"
xmlns="http://www.w3.org/2005/Atom"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="html:body">
<feed>
<id>
<xsl:value-of select="@data-unique-id"/>
</id>
<title>
<xsl:value-of select="../html:head/html:title"/>
</title>
<updated>
<xsl:for-each select="//html:time[@datetime]">
<xsl:sort select="@datetime" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="@datetime"/>
</xsl:if>
</xsl:for-each>
</updated>
<xsl:apply-templates/>
</feed>
</xsl:template>
<xsl:template match="html:article">
<entry>
<id>
<xsl:value-of select="@data-unique-id"/>
</id>
<updated>
<xsl:value-of select=".//html:time/@datetime"/>
</updated>
<author>
<name>
<xsl:value-of select="normalize-space(.//html:span[@class = 'teaser-small__byline'])"/>
</name>
</author>
<title>
<xsl:value-of select="normalize-space(.//html:h2)"/>
</title>
<summary type="text">
<xsl:value-of select="normalize-space(.//html:p)"/>
</summary>
<link rel="alternate" href="{.//html:h2/html:a/@href}"/>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="document(@data-unique-id)//body" mode="copy-content"/>
</div>
</content>
</entry>
</xsl:template>
<xsl:template match="division" mode="copy-content">
<xsl:element name="div" namespace="http://www.w3.org/1999/xhtml">
<xsl:apply-templates mode="copy-content"/>
</xsl:element>
</xsl:template>
<xsl:template match="title" mode="copy-content">
<xsl:element name="h1" namespace="http://www.w3.org/1999/xhtml">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="subtitle" mode="copy-content">
<xsl:element name="h2" namespace="http://www.w3.org/1999/xhtml">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="intertitle" mode="copy-content">
<xsl:element name="h3" namespace="http://www.w3.org/1999/xhtml">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="a" mode="copy-content">
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="copy-content"/>
</xsl:element>
</xsl:template>
<xsl:template match="p | br | em | strong" mode="copy-content">
<xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
<xsl:apply-templates mode="copy-content"/>
</xsl:element>
</xsl:template>
<xsl:template match="text()"/>
</xsl:transform>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment