Skip to content

Instantly share code, notes, and snippets.

@uniquelau
Created September 14, 2011 09:08
Show Gist options
  • Save uniquelau/1216153 to your computer and use it in GitHub Desktop.
Save uniquelau/1216153 to your computer and use it in GitHub Desktop.
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:variable name="style" select="tbc" />
<xsl:variable name="patterns" select="umb:GetXmlDocument('/xslt/grid-patterns.xml' , 1)" />
<xsl:variable name="patternTotal" select="count($patterns/patterns/pattern [@name = $pattern]/* )" />
<!-- Grid Blocks -->
<xsl:template name="news-block" match="publicNewsArticle">
<xsl:variable name="seqPosition" select="round((position()-1) div $patternTotal)" />
<xsl:variable name="index" select="(position()-($seqPosition * $patternTotal))" />
<xsl:variable name="style" select="$patterns/patterns/pattern/style[number($index)]"/>
<!-- Image Block -->
<xsl:if test="$style/@preImage !=''">
<div class="block"><img src="{$style/@preImage}" /></div>
</xsl:if>
<!-- Article Block -->
<a href="{umb:NiceUrl(@id)}" class="block {$style/@name}">
<h2>
<xsl:value-of select="umb:FormatDateTime(contentDate, 'dd MMMM yyyy')"/>
</h2>
<xsl:value-of select="contentTeaser" disable-output-escaping="yes"/>
</a>
</xsl:template>
</xsl:stylesheet>
<!-- Input XML Document for Reference -->
<!-- Pattern - XML Document for Reference -->
<?xml version="1.0" encoding="utf-8" ?>
<patterns>
<pattern name="news">
<style name="dark" />
<style name="light" />
<style name="dark" preImage="http://placehold.it/150x150"/>
<style name="white" />
<style name="dark" />
<style name="light" preImage="http://placehold.it/150x150"/>
<style name="white" />
</pattern>
</patterns>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment