|
| 1 | +<?xml version='1.0' encoding="ISO-8859-1"?> |
| 2 | +<xsl:stylesheet |
| 3 | + xmlns:xsl='http://www.w3.org/1999/XSL/Transform' |
| 4 | + xmlns:media="http://search.yahoo.com/mrss/" |
| 5 | + xmlns:a="http://www.w3.org/2005/Atom" |
| 6 | + xmlns:h='http://www.w3.org/1999/xhtml' |
| 7 | + exclude-result-prefixes="a media" |
| 8 | + version='1.1' |
| 9 | + > |
| 10 | +<!-- merge feeds into one item if content/@type="xhtml" and contains at least one img --> |
| 11 | +<xsl:output method="xml" indent="yes"/> |
| 12 | + |
| 13 | + |
| 14 | +<xsl:template match="/"> |
| 15 | +<xsl:apply-templates select="a:feed"/> |
| 16 | +</xsl:template> |
| 17 | + |
| 18 | +<xsl:template match="a:feed"> |
| 19 | +<xsl:variable name="items" select="a:entry[a:content/@type='xhtml' and count(a:content//h:img) > 0]"/> |
| 20 | +<feed xmlns="http://www.w3.org/2005/Atom"> |
| 21 | +<xsl:apply-templates select="a:updated|a:id|a:icon|a:link|a:logo|a:title|a:subtite" mode="cp"/> |
| 22 | +<xsl:if test="count($items) > 0"> |
| 23 | +<entry> |
| 24 | +<author> |
| 25 | + <name><xsl:value-of select="a:title"/></name> |
| 26 | + <uri><xsl:value-of select="a:link[@rel='alternate']/@href"/></uri> |
| 27 | +</author> |
| 28 | + <updated><xsl:value-of select="$items[1]/a:updated/text()"/></updated> |
| 29 | + <id><xsl:value-of select="$items[1]/a:id/text()"/></id> |
| 30 | + <link><xsl:attribute name="href"><xsl:value-of select="a:link[@rel='alternate']/@href"/></xsl:attribute></link> |
| 31 | + <content type="xhtml"> |
| 32 | + <div xmlns="http://www.w3.org/1999/xhtml"> |
| 33 | + <xsl:apply-templates select="$items"/> |
| 34 | + </div> |
| 35 | + </content> |
| 36 | +</entry> |
| 37 | +</xsl:if> |
| 38 | +</feed> |
| 39 | +</xsl:template> |
| 40 | + |
| 41 | +<xsl:template match="a:entry"> |
| 42 | +<xsl:apply-templates select=".//h:img"/> |
| 43 | +</xsl:template> |
| 44 | + |
| 45 | +<xsl:template match="h:img"> |
| 46 | +<a xmlns="http://www.w3.org/1999/xhtml" target="_blank"> |
| 47 | +<xsl:attribute name="href"><xsl:value-of select="./ancestor::a:entry/a:link/@href"/></xsl:attribute> |
| 48 | +<xsl:apply-templates select="." mode="cp"/> |
| 49 | +</a> |
| 50 | +</xsl:template> |
| 51 | + |
| 52 | + |
| 53 | +<xsl:template match="@*|node()" mode="cp"> |
| 54 | + <xsl:copy> |
| 55 | + <xsl:apply-templates select="@*|node()" mode="cp"/> |
| 56 | + </xsl:copy> |
| 57 | +</xsl:template> |
| 58 | + |
| 59 | + |
| 60 | +</xsl:stylesheet> |
0 commit comments