Aristotle (edge_walker) wrote in lj_nifty,
Aristotle
edge_walker
lj_nifty

Debastardizing LJ’s Atom 0.3-that-wants-to-be-1.0-when-it-grows-up

Addendum: since the latest changes, this code is obsolete. Thanks, Livejournal crew.

I noticed that LJ has started emitting a weird bastard format that looks like Atom 0.3 and Atom 1.0 together in the same document. Because the fulltext is embedded according to the Atom 1.0 conventions, but in namespace-less elements, no strictly conformant aggregator can find it – neither ones which support Atom 0.3 nor those which support Atom 1.0. Only clients which do not actually use an XML parser can make heads or tails of the current format.

<inset type="political">

I find that very unfortunate, as the Atom WG has always stressed standards compliance as a prerequisite for Atom processors and the format was supposed to clean up the murky swamps of RSS.

Still, I am glad to see LJ is at least moving to upgrade from the deprecated 0.3 format. I hope the transitory period with this bastard format is short.

</inset>

The current state of affairs amounts to title-only feeds for users of compliant aggregators, such as Liferea (my reader of choice). So I wrote an XSLT transform to generate a clean and proper Atom 1.0 feed:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:a03="http://purl.org/atom/ns#"
 xmlns="http://www.w3.org/2005/Atom"
>

<xsl:output
 method="xml"
 indent="no"
 encoding="utf-8"
/>

<!-- identity copy -->
<xsl:template match="node()|@*">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="a03:*" />


<xsl:template
 match="a03:feed | a03:id | a03:title
 | a03:subtitle | a03:author | a03:email
 | a03:name | a03:link | a03:published
 | a03:updated | a03:entry | category | content"
>
 <xsl:element name="{ local-name() }">
  <xsl:apply-templates select="@*|node()"/>
 </xsl:element>
</xsl:template>

</xsl:stylesheet>

Assuming you have saved this as /home/yourname/.liferea/debastardise-lj-atom.xslt, you can use it in Liferea by bringing up a feed’s properties, checking Use conversion filter on the Feed Source tab, and entering the following filter command:

xsltproc /home/yourname/debastardize-lj-atom.xslt -

This requires xsltproc, of course, which is libxslt’s commandline processor. It is common on Linux/Unix systems because libxslt is required for GNOME. But any other available XSLT processor will do; your aggregator may even have one built in.

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 11 comments