OPML processing processing
- 1. Merge opml files, blog listings
1. | Merge opml files, blog listings |
| Dave Pawson
I've long run three different sets of blog lists on
3 different PC's. Each time I keep thinking what was
that blog on the other PC?
I've finally written a merge stylesheet.
Takes two opml files and merges them into one.
Enjoy.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.dpawson.co.uk/ns#"
xmlns:xs="http://www.w3.org/2001/XMLSchema-datatypes"
exclude-result-prefixes='dp xs'
version="2.0">
<xsl:param name='file1' select='"a.xml"'/>
<xsl:param name='file2' select='"b.xml"'/>
<xsl:variable name="second">
<xsl:choose>
<xsl:when test="doc-available($file2)">
<xsl:sequence select="document($file2/opml/body/outline/*)"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate='yes'>
Invalid second file <xsl:value-of select="$file2"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/" name='initial'>
<xsl:if test="$file1='a.xml' and $file2='bxml'">
<xsl:message terminate='yes'>
Usage: sax2 -it initial file1.opml file2.opml
</xsl:message>
</xsl:if>
<opml version="1.0">
<head>
<title>Merged <xsl:value-of select="current-dateTime()"/></title>
</head>
<body>
<xsl:apply-templates select="document($file1)/opml/body/outline/*">
<xsl:sort select="@text"/>
</xsl:apply-templates>
</body>
</opml>
</xsl:template>
<xsl:template match="body/outline">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="outline | $second"/>
</xsl:copy>
</xsl:template>
<xsl:template match="outline">
<xsl:copy>
<xsl:copy-of select="@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
|