Skip to content

Instantly share code, notes, and snippets.

@MrBlank
Created May 5, 2009 16:20

Revisions

  1. MrBlank revised this gist Jul 12, 2009. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions basic-tumbler.xsl
    Original file line number Diff line number Diff line change
    @@ -76,7 +76,7 @@
    </xsl:apply-templates>
    <xsl:if test="regular-title">
    <h3>
    <a href="{@url}" title="Permalink to this post on Tumblr">
    <a href="{.}" title="Permalink to this post on Tumblr">
    <xsl:value-of select="regular-title"/>
    </a>
    </h3>
    @@ -209,7 +209,7 @@
    <div class="meta">
    <xsl:value-of select="$label"/>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    <a href="{.}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    </xsl:template>

  2. MrBlank revised this gist Jun 24, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion basic-tumbler.xsl
    Original file line number Diff line number Diff line change
    @@ -216,7 +216,7 @@
    <!-- Output from a text area -->
    <xsl:template match="*" mode="tumblr-body">
    <div class="{name(.)}">
    <!-- If there is only 1 paragraph in a text area, Tumbler doesn't output <p> tags. This makes consistent styling difficult. -->
    <!-- If there is only 1 paragraph in a text area, Tumbler doesn't output <p> tags. This makes consistent styling difficult. http://getsatisfaction.com/tumblr/topics/why_does_tumblr_strip_p_tags_from_posts -->
    <!-- The <choose> statement below checks for <p>, <h1-6> and <blockquote> tags. If they don't exist, it adds the <p> tag. -->
    <!-- If you don't like this, remove the <choose> and replace it with this: <xsl:value-of select="regular-body" disable-output-escaping="yes"/> -->
    <xsl:choose>
  3. MrBlank revised this gist May 15, 2009. 1 changed file with 15 additions and 14 deletions.
    29 changes: 15 additions & 14 deletions basic-tumbler.xsl
    Original file line number Diff line number Diff line change
    @@ -179,32 +179,33 @@
    </div>
    </xsl:if>
    <ol>
    <xsl:for-each select="conversation/line">
    <li>
    <!-- This adds a class of "odd" to every other <li> so you can zebra stripe chats. -->
    <xsl:if test="(position() mod 2) = 1">
    <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>
    <span><xsl:value-of select="@name"/></span>
    <xsl:text>: </xsl:text>
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </li>
    </xsl:for-each>
    <xsl:for-each select="conversation/line">
    <li>
    <!-- This adds a class of "odd" to every other <li> so you can zebra stripe chats. -->
    <xsl:if test="(position() mod 2) = 1">
    <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>
    <span><xsl:value-of select="@name"/></span>
    <xsl:text>: </xsl:text>
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </li>
    </xsl:for-each>
    </ol>
    </div>
    </xsl:when>

    <!-- End types -->
    </xsl:choose>

    <!-- End post types -->
    </xsl:for-each>
    </div>
    </xsl:for-each>
    </xsl:template>

    <!-- Meta information for each post -->
    <xsl:template match="@url" mode="tumblr-meta">
    <xsl:param name="label"/>

    <xsl:param name="label"/>

    <div class="meta">
    <xsl:value-of select="$label"/>
    <xsl:text> // </xsl:text>
  4. MrBlank revised this gist May 15, 2009. 1 changed file with 71 additions and 135 deletions.
    206 changes: 71 additions & 135 deletions basic-tumbler.xsl
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!--
    Name: Basic Tumbler.com API Utility
    Version: 1.0
    Version: 1.1
    Author: Josh Nichols <mrblank@gmail.com>
    URL: http://www.joshnichols.com/
    @@ -43,7 +43,7 @@
    </p>
    </div>
    </xsl:template>

    <!-- Groups posts by day using the Key value -->
    <xsl:template match="posts">
    <xsl:for-each select="post[generate-id() = generate-id (key('post-date', substring(@date, 6, 11))[1])]">
    <div class="tumblr-entries">
    @@ -65,17 +65,15 @@
    </xsl:choose>
    </span>
    </div>

    <!-- Post types -->
    <xsl:for-each select="key('post-date', substring(@date, 6, 11))">
    <xsl:choose>

    <!-- Regular type -->
    <xsl:when test="@type='regular'">
    <div class="tumblr-entry regular">
    <div class="meta">
    <xsl:text>Update</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Image'"/>
    </xsl:apply-templates>
    <xsl:if test="regular-title">
    <h3>
    <a href="{@url}" title="Permalink to this post on Tumblr">
    @@ -84,66 +82,29 @@
    </h3>
    </xsl:if>
    <div class="regular-body">
    <!-- If there is only 1 paragraph in a text area, Tumbler doesn't output <p> tags. This makes consistent styling difficult. -->
    <!-- The <choose> statement below checks for <p>, <h1-6> and <blockquote> tags. If they don't exist, it adds the <p> tag. -->
    <!-- If you don't like this, remove the <choose> and replace it with this: <xsl:value-of select="regular-body" disable-output-escaping="yes"/> -->
    <xsl:choose>
    <xsl:when test="substring(regular-body, 1, 2) = '&lt;p'">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(regular-body, 1, 2) = '&lt;h'">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(regular-body, 1, 2) = '&lt;b'">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="regular-body" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates select="regular-body" mode="tumblr-body"/>
    </div>
    </div>
    </xsl:when>

    <!-- Type photo -->
    <xsl:when test="@type='photo'">
    <div class="tumblr-entry photo">
    <div class="meta">
    <xsl:text>Image</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Image'"/>
    </xsl:apply-templates>
    <div class="photo-url">
    <!-- image "max-width" sizes are 75, 100, 250, 400 and 500 -->
    <img src="{photo-url[@max-width='500']}" alt="Tumblelog image"/>
    </div>
    <xsl:if test="photo-caption">
    <div class="photo-caption">
    <xsl:choose>
    <xsl:when test="substring(photo-caption, 1, 2) = '&lt;p'">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(photo-caption, 1, 2) = '&lt;h'">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(photo-caption, 1, 2) = '&lt;b'">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="photo-caption" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    <xsl:apply-templates select="photo-caption" mode="tumblr-body"/>
    </div>
    </xsl:when>

    <!-- Link text -->
    <xsl:when test="@type='link'">
    <div class="tumblr-entry link">
    <div class="meta">
    <xsl:text>Link</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Link'"/>
    </xsl:apply-templates>
    <xsl:choose>
    <xsl:when test="link-text">
    <h3>
    @@ -160,34 +121,15 @@
    </p>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="link-description">
    <div class="link-description">
    <xsl:choose>
    <xsl:when test="substring(link-description, 1, 2) = '&lt;p'">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(link-description, 1, 2) = '&lt;h'">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(link-description, 1, 2) = '&lt;b'">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="link-description" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    <xsl:apply-templates select="link-description" mode="tumblr-body"/>
    </div>
    </xsl:when>

    <!-- Quote type -->
    <xsl:when test="@type='quote'">
    <div class="tumblr-entry quote">
    <div class="meta">
    <xsl:text>Quote</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Quote'"/>
    </xsl:apply-templates>
    <blockquote>
    <xsl:value-of select="quote-text" disable-output-escaping="yes"/>
    </blockquote>
    @@ -198,79 +140,39 @@
    </xsl:if>
    </div>
    </xsl:when>

    <!-- Video type -->
    <xsl:when test="@type='video'">
    <div class="tumblr-entry video">
    <div class="meta">
    <xsl:text>Video</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Video'"/>
    </xsl:apply-templates>
    <div class="video-embed">
    <!-- Using "video-player" makes videos 400px wide, "video-source" uses the source dimentions. -->
    <xsl:value-of select="video-source" disable-output-escaping="yes"/>
    <xsl:value-of select="video-player" disable-output-escaping="yes"/>
    </div>
    <xsl:if test="video-caption">
    <div class="video-caption">
    <xsl:choose>
    <xsl:when test="substring(video-caption, 1, 2) = '&lt;p'">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(video-caption, 1, 2) = '&lt;h'">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(video-caption, 1, 2) = '&lt;b'">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="video-caption" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    <xsl:apply-templates select="video-caption" mode="tumblr-body"/>
    </div>
    </xsl:when>

    <!-- Audio type -->
    <xsl:when test="@type='audio'">
    <div class="tumblr-entry audio">
    <div class="meta">
    <xsl:text>Audio</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Audio'"/>
    </xsl:apply-templates>
    <div class="audio-player">
    <xsl:value-of select="substring-before(audio-player,'.swf')" disable-output-escaping="yes"/>
    <xsl:text>_black</xsl:text>
    <xsl:value-of select="substring-after(audio-player,'audio_player')" disable-output-escaping="yes"/>
    </div>
    <xsl:if test="audio-caption">
    <div class="audio-caption">
    <xsl:choose>
    <xsl:when test="substring(audio-caption, 1, 2) = '&lt;p'">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(audio-caption, 1, 2) = '&lt;h'">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(audio-caption, 1, 2) = '&lt;b'">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="audio-caption" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    <xsl:apply-templates select="audio-caption" mode="tumblr-body"/>
    </div>
    </xsl:when>

    <!-- Chat type -->
    <xsl:when test="@type='conversation'">
    <div class="tumblr-entry conversation">
    <div class="meta">
    <xsl:text>Chat</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:apply-templates select="@url" mode="tumblr-meta">
    <xsl:with-param name="label" select="'Chat'"/>
    </xsl:apply-templates>
    <xsl:if test="conversation-title">
    <div class="conversation-title">
    <h3><xsl:value-of select="conversation-title"/></h3>
    @@ -298,5 +200,39 @@
    </div>
    </xsl:for-each>
    </xsl:template>

    <!-- Meta information for each post -->
    <xsl:template match="@url" mode="tumblr-meta">
    <xsl:param name="label"/>

    <div class="meta">
    <xsl:value-of select="$label"/>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    </xsl:template>

    <!-- Output from a text area -->
    <xsl:template match="*" mode="tumblr-body">
    <div class="{name(.)}">
    <!-- If there is only 1 paragraph in a text area, Tumbler doesn't output <p> tags. This makes consistent styling difficult. -->
    <!-- The <choose> statement below checks for <p>, <h1-6> and <blockquote> tags. If they don't exist, it adds the <p> tag. -->
    <!-- If you don't like this, remove the <choose> and replace it with this: <xsl:value-of select="regular-body" disable-output-escaping="yes"/> -->
    <xsl:choose>
    <xsl:when test="substring(., 1, 2) = '&lt;p'">
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(., 1, 2) = '&lt;h'">
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(., 1, 2) = '&lt;b'">
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="." disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:template>

    </xsl:stylesheet>
  5. MrBlank renamed this gist May 7, 2009. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. MrBlank revised this gist May 7, 2009. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Basic Tumbler.com API Utility
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,7 @@
    URL: http://www.joshnichols.com/
    Description:
    This utility transforms a basic Tumblr XML source. Each post is grouped by date and is marked up in a way that alows for easy styling with CSS.
    This utility transforms a basic Tumblr.com XML source into XHTML. Each post is grouped by date and is marked up in a way that allows for easy styling with CSS.
    Data source:
    Requires a Dynamic XML data source using Tumblr.com's API named "get-tumblr". API documentation: http://www.tumblr.com/api
    Example: http://mrblank.tumblr.com/api/read/
  7. MrBlank revised this gist May 7, 2009. 1 changed file with 119 additions and 21 deletions.
    140 changes: 119 additions & 21 deletions Basic Tumbler.com API Utility
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,26 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- Name: Basic Tumbler.com API Utility
    Version: 0.8
    <!--
    Name: Basic Tumbler.com API Utility
    Version: 1.0
    Author: Josh Nichols <mrblank@gmail.com>
    URL: http://www.joshnichols.com/
    Description:
    This utility transforms a basic Tumblr XML source. Each post is grouped by date and is marked up in a way that alows for easy styling with CSS.
    Data source:
    Requires a Dynamic XML data source using Tumblr.com's API named "tumblr". API documentation: http://www.tumblr.com/api
    Requires a Dynamic XML data source using Tumblr.com's API named "get-tumblr". API documentation: http://www.tumblr.com/api
    Example: http://mrblank.tumblr.com/api/read/
    To do:
    Create a template for a "chat" post type
    Include some starter CSS rules.
    -->

    <xsl:key name="post-date" match="post" use="substring(@date, 6, 11)"/>

    <!-- The template matches on the name of your Tumblr data source -->
    <xsl:template match="tumblr">
    <xsl:template match="get-tumblr">

    <xsl:param name="tumblr-url" select="tumblr/tumblelog/@cname"/>
    <xsl:param name="tumblr-name" select="tumblr/tumblelog/@title"/>
    @@ -48,6 +49,9 @@
    <xsl:for-each select="post[generate-id() = generate-id (key('post-date', substring(@date, 6, 11))[1])]">
    <div class="tumblr-entries">
    <div class="date">
    <span class="year">
    <xsl:value-of select="substring(@date, 13, 4)"/>
    </span>
    <span class="month">
    <xsl:value-of select="substring(@date, 9, 3)"/>
    </span>
    @@ -69,10 +73,7 @@
    <xsl:when test="@type='regular'">
    <div class="tumblr-entry regular">
    <div class="meta">
    <xsl:text>Update </xsl:text>
    <xsl:if test="@from-feed-id = '199506'">
    <a href="http://twitter.com/mrblank">via Twitter</a>
    </xsl:if>
    <xsl:text>Update</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    @@ -84,25 +85,54 @@
    </h3>
    </xsl:if>
    <div class="regular-body">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    <!-- If there is only 1 paragraph in a text area, Tumbler doesn't output <p> tags. This makes consistent styling difficult. -->
    <!-- The <choose> statement below checks for <p>, <h1-6> and <blockquote> tags. If they don't exist, it adds the <p> tag. -->
    <!-- If you don't like this, remove the <choose> and replace it with this: <xsl:value-of select="regular-body" disable-output-escaping="yes"/> -->
    <xsl:choose>
    <xsl:when test="substring(regular-body, 1, 2) = '&lt;p'">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(regular-body, 1, 2) = '&lt;h'">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(regular-body, 1, 2) = '&lt;b'">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="regular-body" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </div>
    </xsl:when>

    <xsl:when test="@type='photo'">
    <div class="tumblr-entry photo">
    <div class="meta">
    <xsl:text>Image </xsl:text>
    <xsl:text>Image</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <div class="photo-url">
    <!-- image "max-width" sizes are 75, 100, 250, 400 and 500 -->
    <img src="{photo-url[@max-width='400']}" alt="Tumblelog image"/>
    <img src="{photo-url[@max-width='500']}" alt="Tumblelog image"/>
    </div>
    <xsl:if test="photo-caption">
    <div class="photo-caption">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    <xsl:choose>
    <xsl:when test="substring(photo-caption, 1, 2) = '&lt;p'">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(photo-caption, 1, 2) = '&lt;h'">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(photo-caption, 1, 2) = '&lt;b'">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="photo-caption" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    </div>
    @@ -111,7 +141,7 @@
    <xsl:when test="@type='link'">
    <div class="tumblr-entry link">
    <div class="meta">
    <xsl:text>Link </xsl:text>
    <xsl:text>Link</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    @@ -133,7 +163,20 @@
    </xsl:choose>
    <xsl:if test="link-description">
    <div class="link-description">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    <xsl:choose>
    <xsl:when test="substring(link-description, 1, 2) = '&lt;p'">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(link-description, 1, 2) = '&lt;h'">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(link-description, 1, 2) = '&lt;b'">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="link-description" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    </div>
    @@ -142,7 +185,7 @@
    <xsl:when test="@type='quote'">
    <div class="tumblr-entry quote">
    <div class="meta">
    <xsl:text>Quote </xsl:text>
    <xsl:text>Quote</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    @@ -160,16 +203,30 @@
    <xsl:when test="@type='video'">
    <div class="tumblr-entry video">
    <div class="meta">
    <xsl:text>Video </xsl:text>
    <xsl:text>Video</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <div class="video-embed">
    <xsl:value-of select="video-player" disable-output-escaping="yes"/>
    <!-- Using "video-player" makes videos 400px wide, "video-source" uses the source dimentions. -->
    <xsl:value-of select="video-source" disable-output-escaping="yes"/>
    </div>
    <xsl:if test="video-caption">
    <div class="video-caption">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    <xsl:choose>
    <xsl:when test="substring(video-caption, 1, 2) = '&lt;p'">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(video-caption, 1, 2) = '&lt;h'">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(video-caption, 1, 2) = '&lt;b'">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="video-caption" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    </div>
    @@ -178,7 +235,7 @@
    <xsl:when test="@type='audio'">
    <div class="tumblr-entry audio">
    <div class="meta">
    <xsl:text>Audio </xsl:text>
    <xsl:text>Audio</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    @@ -189,9 +246,50 @@
    </div>
    <xsl:if test="audio-caption">
    <div class="audio-caption">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    <xsl:choose>
    <xsl:when test="substring(audio-caption, 1, 2) = '&lt;p'">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(audio-caption, 1, 2) = '&lt;h'">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:when test="substring(audio-caption, 1, 2) = '&lt;b'">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <p><xsl:value-of select="audio-caption" disable-output-escaping="yes"/></p>
    </xsl:otherwise>
    </xsl:choose>
    </div>
    </xsl:if>
    </div>
    </xsl:when>

    <xsl:when test="@type='conversation'">
    <div class="tumblr-entry conversation">
    <div class="meta">
    <xsl:text>Chat</xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:if test="conversation-title">
    <div class="conversation-title">
    <h3><xsl:value-of select="conversation-title"/></h3>
    </div>
    </xsl:if>
    <ol>
    <xsl:for-each select="conversation/line">
    <li>
    <!-- This adds a class of "odd" to every other <li> so you can zebra stripe chats. -->
    <xsl:if test="(position() mod 2) = 1">
    <xsl:attribute name="class">odd</xsl:attribute>
    </xsl:if>
    <span><xsl:value-of select="@name"/></span>
    <xsl:text>: </xsl:text>
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </li>
    </xsl:for-each>
    </ol>
    </div>
    </xsl:when>

  8. MrBlank revised this gist May 5, 2009. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions Basic Tumbler.com API Utility
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--
    Name: Basic Tumbler.com API Utility
    <!-- Name: Basic Tumbler.com API Utility
    Version: 0.8
    Author: Josh Nichols <mrblank@gmail.com>
    URL: http://www.joshnichols.com/
  9. MrBlank created this gist May 5, 2009.
    207 changes: 207 additions & 0 deletions Basic Tumbler.com API Utility
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,207 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <!--
    Name: Basic Tumbler.com API Utility
    Version: 0.8
    Author: Josh Nichols <mrblank@gmail.com>
    URL: http://www.joshnichols.com/
    Description:
    This utility transforms a basic Tumblr XML source. Each post is grouped by date and is marked up in a way that alows for easy styling with CSS.
    Data source:
    Requires a Dynamic XML data source using Tumblr.com's API named "tumblr". API documentation: http://www.tumblr.com/api
    Example: http://mrblank.tumblr.com/api/read/
    To do:
    Create a template for a "chat" post type
    -->

    <xsl:key name="post-date" match="post" use="substring(@date, 6, 11)"/>

    <!-- The template matches on the name of your Tumblr data source -->
    <xsl:template match="tumblr">

    <xsl:param name="tumblr-url" select="tumblr/tumblelog/@cname"/>
    <xsl:param name="tumblr-name" select="tumblr/tumblelog/@title"/>
    <xsl:param name="tumblr-description" select="tumblr/tumblelog"/>

    <div id="tumblelog">
    <h2><xsl:value-of select="$tumblr-name"/></h2>
    <p><xsl:value-of select="$tumblr-description"/></p>
    <xsl:choose>
    <xsl:when test="error">
    <div class="entries">
    <p>The Tumblr.com feed is down right now, sorry. <a href="http://{$tumblr-url}">Try visiting my Tumblelog there</a>, or check back later.</p>
    </div>
    </xsl:when>
    <xsl:otherwise>
    <xsl:apply-templates select="tumblr/posts"/>
    </xsl:otherwise>
    </xsl:choose>
    <p>
    <a href="http://{$tumblr-url}/archive">Browse the tumblelog archive &#8594;</a>
    </p>
    </div>
    </xsl:template>

    <xsl:template match="posts">
    <xsl:for-each select="post[generate-id() = generate-id (key('post-date', substring(@date, 6, 11))[1])]">
    <div class="tumblr-entries">
    <div class="date">
    <span class="month">
    <xsl:value-of select="substring(@date, 9, 3)"/>
    </span>
    <span class="day">
    <xsl:choose>
    <xsl:when test="substring(@date, 6, 1) = 0">
    <xsl:value-of select="substring(@date, 7, 1)"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="substring(@date, 6, 2)"/>
    </xsl:otherwise>
    </xsl:choose>
    </span>
    </div>

    <xsl:for-each select="key('post-date', substring(@date, 6, 11))">
    <xsl:choose>

    <xsl:when test="@type='regular'">
    <div class="tumblr-entry regular">
    <div class="meta">
    <xsl:text>Update </xsl:text>
    <xsl:if test="@from-feed-id = '199506'">
    <a href="http://twitter.com/mrblank">via Twitter</a>
    </xsl:if>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:if test="regular-title">
    <h3>
    <a href="{@url}" title="Permalink to this post on Tumblr">
    <xsl:value-of select="regular-title"/>
    </a>
    </h3>
    </xsl:if>
    <div class="regular-body">
    <xsl:value-of select="regular-body" disable-output-escaping="yes"/>
    </div>
    </div>
    </xsl:when>

    <xsl:when test="@type='photo'">
    <div class="tumblr-entry photo">
    <div class="meta">
    <xsl:text>Image </xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <div class="photo-url">
    <!-- image "max-width" sizes are 75, 100, 250, 400 and 500 -->
    <img src="{photo-url[@max-width='400']}" alt="Tumblelog image"/>
    </div>
    <xsl:if test="photo-caption">
    <div class="photo-caption">
    <xsl:value-of select="photo-caption" disable-output-escaping="yes"/>
    </div>
    </xsl:if>
    </div>
    </xsl:when>

    <xsl:when test="@type='link'">
    <div class="tumblr-entry link">
    <div class="meta">
    <xsl:text>Link </xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <xsl:choose>
    <xsl:when test="link-text">
    <h3>
    <a href="{link-url}" title="Visit this link">
    <xsl:value-of select="link-text"/>
    </a>
    </h3>
    </xsl:when>
    <xsl:otherwise>
    <p>
    <a href="{link-url}" title="Visit this link">
    <xsl:value-of select="link-url"/>
    </a>
    </p>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="link-description">
    <div class="link-description">
    <xsl:value-of select="link-description" disable-output-escaping="yes"/>
    </div>
    </xsl:if>
    </div>
    </xsl:when>

    <xsl:when test="@type='quote'">
    <div class="tumblr-entry quote">
    <div class="meta">
    <xsl:text>Quote </xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <blockquote>
    <xsl:value-of select="quote-text" disable-output-escaping="yes"/>
    </blockquote>
    <xsl:if test="quote-source">
    <div class="quote-source">
    <p>&#8212; <xsl:value-of select="quote-source" disable-output-escaping="yes"/></p>
    </div>
    </xsl:if>
    </div>
    </xsl:when>

    <xsl:when test="@type='video'">
    <div class="tumblr-entry video">
    <div class="meta">
    <xsl:text>Video </xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <div class="video-embed">
    <xsl:value-of select="video-player" disable-output-escaping="yes"/>
    </div>
    <xsl:if test="video-caption">
    <div class="video-caption">
    <xsl:value-of select="video-caption" disable-output-escaping="yes"/>
    </div>
    </xsl:if>
    </div>
    </xsl:when>

    <xsl:when test="@type='audio'">
    <div class="tumblr-entry audio">
    <div class="meta">
    <xsl:text>Audio </xsl:text>
    <xsl:text> // </xsl:text>
    <a href="{@url}" title="Permalink to this post on Tumblr">Permalink &#8734;</a>
    </div>
    <div class="audio-player">
    <xsl:value-of select="substring-before(audio-player,'.swf')" disable-output-escaping="yes"/>
    <xsl:text>_black</xsl:text>
    <xsl:value-of select="substring-after(audio-player,'audio_player')" disable-output-escaping="yes"/>
    </div>
    <xsl:if test="audio-caption">
    <div class="audio-caption">
    <xsl:value-of select="audio-caption" disable-output-escaping="yes"/>
    </div>
    </xsl:if>
    </div>
    </xsl:when>

    </xsl:choose>

    </xsl:for-each>
    </div>
    </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>