Sites-Camelia/branches/divan-dit-vent/scripts/rss.xslt

237 lines
9.9 KiB
HTML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="1.0">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
<xsl:variable name="title" select="/rss/channel/title" />
<xsl:variable name="feedDesc" select="/rss/channel/description" />
<xsl:variable name="copyright" select="/rss/channel/copyright" />
<xsl:template match="/">
<xsl:element name="html">
<head>
<link href="scripts/stylerss.css" rel="stylesheet" type="text/css" media="all" />
<title>
<xsl:value-of select="$title" />
</title>
</head>
<xsl:apply-templates select="rss/channel" />
</xsl:element>
</xsl:template>
<xsl:template match="channel">
<body>
<div>
<div class="top-block">
<xsl:apply-templates select="image" />
<div class="top-description">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="/rss/channel/link[1]" xmlns:atom="http://www.w3.org/2005/Atom" />
</xsl:attribute>
<xsl:value-of select="$title" />
</xsl:element>
<div class="description-block">
<div class="description">
<p>
<xsl:call-template name="hyperlink">
<xsl:with-param name="string" select="$feedDesc" />
</xsl:call-template>
</p>
<p class="copyright">Retrouvez ce podcast sur
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="/rss/channel/link[1]" xmlns:atom="http://www.w3.org/2005/Atom" />
</xsl:attribute>
<xsl:value-of select="/rss/channel/link[1]" />
</xsl:element>
<xsl:if test="/rss/channel/facebook != '' and /rss/channel/facebook != 'https://'">
- Facebook
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="/rss/channel/facebook" xmlns:atom="http://www.w3.org/2005/Atom" />
</xsl:attribute>
<xsl:value-of select="/rss/channel/facebook" />
</xsl:element>
</xsl:if >
<xsl:if test="/rss/channel/twitter != '' and /rss/channel/twitter != 'https://'">
- Twitter
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="/rss/channel/twitter" xmlns:atom="http://www.w3.org/2005/Atom" />
</xsl:attribute>
<xsl:value-of select="/rss/channel/twitter" />
</xsl:element>
</xsl:if >
<xsl:if test="/rss/channel/instagram != '' and /rss/channel/instagram != 'https://'">
- Instagram
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="/rss/channel/instagram" xmlns:atom="http://www.w3.org/2005/Atom" />
</xsl:attribute>
<xsl:value-of select="/rss/channel/instagram" />
</xsl:element>
</xsl:if >
</p>
<p class="copyright">(Auteur : <xsl:value-of select="$copyright" />)</p>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<ul class="episode-list" xmlns="http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="item" />
</ul>
</body>
</xsl:template>
<xsl:template match="image">
<a href="{link}" title="Aller au site">
<xsl:element name="img" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="src">
<xsl:value-of select="url" />
</xsl:attribute>
<xsl:attribute name="width">250</xsl:attribute>
</xsl:element>
</a>
<xsl:text />
</xsl:template>
<!-- One block -->
<xsl:template match="item" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
<li class="episode">
<article>
<xsl:element name="img" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="src">
<xsl:value-of select="image/url" />
</xsl:attribute>
<xsl:attribute name="class">episode-logo</xsl:attribute>
</xsl:element>
<h4 class="itemtitle">
<a class="title" href="{link}">
<xsl:value-of select="title" />
</a>
</h4>
<p class="date">
<xsl:if test="count(child::pubDateaffichage)=1">
<xsl:value-of select="substring(pubDateaffichage, 0, 17)" />
</xsl:if>
<xsl:if test="count(child::dc:date)=1">
<xsl:value-of select="dc:date" />
</xsl:if>
</p>
<xsl:element name="p" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="class">episode-description</xsl:attribute>
<xsl:call-template name="hyperlink">
<xsl:with-param name="string" select="itunes:summary" />
</xsl:call-template>
</xsl:element>
<xsl:if test="count(child::enclosure)&gt;0">
<xsl:if test="contains(enclosure/@type, 'audio')">
<div class="audio-file">
<xsl:variable name="encURL" select="enclosure/@url" xmlns:atom="http://www.w3.org/2005/Atom" />
<div class="audio-content">
<xsl:element name="audio" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="controls" />
<xsl:attribute name="preload">none</xsl:attribute>
<xsl:element name="source" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="src">
<xsl:value-of select="enclosure/@url" />
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="enclosure/@type" />
</xsl:attribute>
</xsl:element>
</xsl:element>
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="class">download</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="enclosure/@url" />
</xsl:attribute>
Télécharger
</xsl:element>
</div>
<div class="audio-file">
</div>
</div>
</xsl:if>
</xsl:if>
</article>
</li>
</xsl:template>
<xsl:template name="outputContent">
<xsl:choose>
<xsl:when xmlns:xhtml="http://www.w3.org/1999/xhtml" test="xhtml:body">
<xsl:copy-of select="xhtml:body/*" />
</xsl:when>
<xsl:when xmlns:xhtml="http://www.w3.org/1999/xhtml" test="xhtml:div">
<xsl:copy-of select="xhtml:div" />
</xsl:when>
<xsl:when xmlns:content="http://purl.org/rss/1.0/modules/content/" test="content:encoded">
<xsl:value-of select="content:encoded" disable-output-escaping="yes" />
</xsl:when>
<xsl:when test="description">
<xsl:value-of select="description" disable-output-escaping="yes" />
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="hyperlink">
<xsl:param name="string" select="string()" />
<xsl:variable name="http">
<xsl:choose>
<xsl:when test="contains($string, 'http://')">
<xsl:text>http://</xsl:text>
</xsl:when>
<xsl:when test="contains($string, 'https://')">
<xsl:text>https://</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$http = 'false'">
<!-- No links, output string -->
<xsl:value-of select="$string"/>
</xsl:when><xsl:otherwise>
<!-- Links detected, replace them -->
<!-- Set up variables -->
<xsl:variable name="before" select="substring-before($string, $http)" />
<xsl:variable name="after" select="substring-after($string, $http)" />
<xsl:variable name="url" select="concat($http, substring-before($after,' '))"/>
<xsl:variable name="rest" select="substring-after($string, $url)" />
<!-- Output the text -->
<xsl:value-of select="$before"/>
<xsl:choose>
<!-- If the url is at then end, $rest doesn't work -->
<xsl:when test="substring-after($url,$http) != ''">
<a href="{$url}" rel="{$url}">
<xsl:value-of select="$url" />
</a>
<!-- Check the remainder for links -->
<xsl:call-template name="hyperlink">
<xsl:with-param name="string" select="$rest"/>
</xsl:call-template>
</xsl:when><xsl:otherwise>
<a href="{$url}{$after}" rel="{$url}{$after}">
<xsl:value-of select="concat($url,$after)" />
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>