Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Michel http://michelc.wordpress.com/

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Blogmarks to Html conversion

This file is intended to transform a Blogmarks atom feed (http://api.blogmarks.net/user/ms_michel) into html code fragment to be included in a complete page.

   1  
   2  <?xml version="1.0" encoding="utf-8"?>
   3  <xsl:stylesheet version="1.0" xmlns:atom="http://purl.org/atom/ns#draft-ietf-atompub-format-05" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/">
   4    <xsl:output method="html" />
   5    <xsl:template match="/">
   6      <xsl:apply-templates select="/atom:feed/atom:head" mode="before" />
   7      <xsl:apply-templates select="/atom:feed/atom:entry" />
   8      <xsl:apply-templates select="/atom:feed/atom:head" mode="after" />
   9    </xsl:template>
  10    <xsl:template match="atom:feed/atom:head" mode="before" >
  11      <!-- <h3><xsl:value-of select="atom:title" /></h3> -->
  12    </xsl:template>
  13    <xsl:template match="atom:feed/atom:head" mode="after">
  14      <p><a href="{atom:link[@rel='alternate']/@href}"><img src="http://blogmarks.net/img/88x31_neg.png" alt="blogmarks.net" /></a></p>
  15    </xsl:template>
  16    <xsl:template match="atom:feed/atom:entry">
  17      <div>
  18        <xsl:choose>
  19          <xsl:when test="position() mod 2 = 1">
  20            <xsl:attribute name="class">bm_blogmarks bm_odd</xsl:attribute>
  21          </xsl:when>
  22          <xsl:otherwise>
  23            <xsl:attribute name="class">bm_blogmarks bm_even</xsl:attribute>
  24          </xsl:otherwise>
  25        </xsl:choose>
  26        <a href="{atom:link[@rel='related']/@href}"><img src="{atom:link[@rel='image']/@href}" alt="" /></a>
  27        <h4><a href="{atom:link[@rel='related']/@href}"><xsl:value-of select="atom:title" /></a></h4>
  28        <p><xsl:value-of select="atom:summary" disable-output-escaping="yes" /></p>
  29        <p class="blogmarks-tags">
  30          <xsl:value-of select="substring(atom:published, 0, 11)" />
  31          <xsl:if test="atom:category">
  32            <xsl:for-each select="atom:category">
  33              <xsl:text> - </xsl:text><a href="{@term}{@sheme}"><xsl:value-of select="@label" /></a>
  34            </xsl:for-each>
  35          </xsl:if>
  36        </p>
  37      </div>
  38    </xsl:template>
  39  </xsl:stylesheet>

The generated html is inspired by the one used on Hot Links (http://dev.upian.com/hotlinks/). It can be styled with the following css:
   1  
   2  .bm_blogmarks {
   3  	margin: 10px auto;
   4  	padding: 1%;
   5  	background-color: #f5f5f5;
   6  	border: 1px solid #d9d9d9;
   7  	width: 97%;
   8  	overflow:auto;
   9  }
  10  .bm_even {
  11      background-color: #fcfcfc;
  12  }
  13  .bm_blogmarks h4 {
  14  	margin-top: 0;
  15  }
  16  .bm_blogmarks p.bm_tags {
  17  	margin-bottom: 0;
  18  	display: block;
  19  	clear: left;
  20  }
  21  .bm_blogmarks img {
  22  	margin: 0 0px 5px 10px;
  23  	float: right;
  24  	border: 0;
  25  	clear: none;
  26  	width: 144px;
  27  	height: 107px;
  28  }
  29  .bm_even img {
  30  	margin: 0 10px 5px 0px;
  31  	float: left;
  32  }

RDF to Html conversion

This file is intended to transform a RDF feed into html code fragment to be included in a complete page.

   1  
   2  <?xml version="1.0" encoding="utf-8"?>
   3  <xsl:stylesheet version="1.0"
   4    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   5    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   6    xmlns:dc="http://purl.org/dc/elements/1.1/"
   7    xmlns:foo="http://purl.org/rss/1.0/">
   8      <xsl:output method="html"/>
   9      <xsl:template match="/">
  10          <xsl:apply-templates select="/rdf:RDF/foo:channel"/>
  11      </xsl:template>
  12      <xsl:template match="/rdf:RDF/foo:channel">
  13          <h3><xsl:value-of select="foo:title"/></h3>
  14          <p><xsl:value-of select="foo:description"/></p>
  15          <ul>
  16              <xsl:apply-templates select="/rdf:RDF/foo:item"/>
  17          </ul>
  18      </xsl:template>
  19      <xsl:template match="/rdf:RDF/foo:item">
  20          <li>
  21              <a href="{foo:link}" title="{substring(dc:date, 0, 11)}"><xsl:value-of select="foo:title"/></a>
  22              <p><xsl:value-of select="foo:description" disable-output-escaping="yes" /></p>
  23          </li>
  24      </xsl:template>
  25  </xsl:stylesheet>

RSS to Html conversion

This file is intended to transform a RSS feed (version 0.9x or 2.0) into html code fragment to be included in a complete page.

   1  
   2  <?xml version="1.0"?>
   3  <xsl:stylesheet version="1.0"
   4   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   5   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
   6      <xsl:output method="html"/>
   7      <xsl:template match="/">
   8          <xsl:apply-templates select="/rss/channel"/>
   9      </xsl:template>
  10      <xsl:template match="/rss/channel">
  11          <h3><xsl:value-of select="title"/></h3>
  12          <p><xsl:value-of select="description"/></p>
  13          <ul>
  14              <xsl:apply-templates select="item"/>
  15          </ul>
  16      </xsl:template>
  17      <xsl:template match="/rss/channel/item">
  18          <li>
  19              <a href="{link}" title="{substring(pubDate, 0, 11)}"><xsl:value-of select="title"/></a>
  20              <p><xsl:value-of select="description" disable-output-escaping="yes" /></p>
  21          </li>
  22      </xsl:template>
  23  </xsl:stylesheet>

Atom to Html conversion

This file is intended to transform an Atom feed into html code fragment to be included in a complete page.

   1  
   2  <?xml version="1.0" encoding="utf-8"?>
   3  <xsl:stylesheet version="1.0"
   4    xmlns:atom="http://purl.org/atom/ns#"
   5    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   6    xmlns:dc="http://purl.org/dc/elements/1.1/">
   7      <xsl:output method="html"/>
   8      <xsl:template match="/">
   9      <xsl:apply-templates select="/atom:feed/atom:head"/>
  10          <xsl:apply-templates select="/atom:feed"/>
  11      </xsl:template>
  12      <xsl:template match="atom:feed/atom:head">
  13          <h3><xsl:value-of select="atom:title"/></h3>
  14          <xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
  15          <xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
  16      </xsl:template>
  17      <xsl:template match="/atom:feed">
  18          <h3><xsl:value-of select="atom:title"/></h3>
  19          <xsl:if test="atom:tagline"><p><xsl:value-of select="atom:tagline"/></p></xsl:if>
  20          <xsl:if test="atom:subtitle"><p><xsl:value-of select="atom:subtitle"/></p></xsl:if>
  21          <ul>
  22              <xsl:apply-templates select="atom:entry"/>
  23          </ul>
  24      </xsl:template>
  25      <xsl:template match="atom:entry">
  26          <li>
  27              <a href="{atom:link[@rel='related']/@href}" title="{substring(atom:published, 0, 11)}"><xsl:value-of select="atom:title"/></a>
  28              <xsl:choose>
  29                  <xsl:when test="atom:content != ''">
  30                      <p><xsl:value-of select="atom:content" disable-output-escaping="yes" /></p>
  31                  </xsl:when>
  32                  <xsl:otherwise>
  33                      <p><xsl:value-of select="atom:summary" disable-output-escaping="yes" /></p>
  34                  </xsl:otherwise>
  35              </xsl:choose>
  36          </li>
  37      </xsl:template>
  38  </xsl:stylesheet>
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS