Skip to content

Instantly share code, notes, and snippets.

@lewiswharf
Forked from andrewminton/master.xml
Created August 11, 2012 14:52
Show Gist options
  • Save lewiswharf/3325052 to your computer and use it in GitHub Desktop.
Save lewiswharf/3325052 to your computer and use it in GitHub Desktop.
<data>
<preferences>
<sitename>Client - Portfolio</sitename>
<languages>
<entry id="1" handle="english" lang="en">English</entry>
<entry id="2" handle="francais" lang="fr">Francais</entry>
</languages>
<stylesheets><entry id="1"><url link="http://link-to-main.stylesheet.css"/></entry></stylesheets>
<scripts><entry id="1"><url link="http://link-to-main.stylesheet.css"/></entry></scripts>
<navlinks>
<entry url="http://domain.co.uk/home"><title lang="en">Home</title></entry>
<entry url="http://domain.co.uk/projects"><title lang="en">Projects</title></entry>
<entry url="http://domain.co.uk/contact"><title lang="en">Contact</title></entry>
<entry url="http://domain.co.uk/about"><title lang="en">About</title></entry>
<entry url="http://domain.co.uk/portfolio"><title lang="en">Portfolio</title></entry>
</navlinks>
<categories>
<entry id="9">
<cat lang="en" handle="construction">Construction</cat>
<cat lang="fr" handle="construcion">Construcion</cat>
</entry>
<entry id="10">
<cat lang="en" handle="forestry">Water Management</cat>
<cat lang="fr" handle="gestion-de-leau">Gestion de leau</cat>
</entry>
<entry id="11">
<cat lang="en" handle="geochemistry">Geochemistry</cat>
<cat lang="fr" handle="geochimie">Geochimie</cat>
</entry>
</categories>
</preferences>
<projects>
<entry id="2" sort-order="0">
<title lang="en">Project title</title>
<title lang="fr">Titre du projet</title>
<description lang="en"><p>some HTML encoded with escaped entities</p></description>
<description lang="fr"><p>some HTML encoded with escaped entities Francais</p></description>
<video lang="en" id="90" url="http://player.vimeo.com/video/47100629?title=0&amp;byline=0&amp;color=c8dd63"/>
<images>
<item lang="en" featured='yes' id="78" url="http://linkto-image-url.jpg"/>
<item lang="en" id="56" url="http://linkto-image-url.jpg"/>
<item lang="fr" id="78" url="http://linkto-image-url.jpg"/>
</images>
<categories>
<cat lang="en">9,10,11</cat>
<cat lang="fr">10,6</cat>
</categories>
<published order="20120812">12-08-2012</published>
</entry>
<entry id="1" sort-order="1">
<title lang="en">Project title</title>
<title lang="fr">Titre du projet</title>
<description lang="en"><p>some HTML encoded with escaped entities</p></description>
<description lang="fr"><p>some HTML encoded with escaped entities Francais</p></description>
<video lang="en" id="90" url="http://player.vimeo.com/video/47100629?title=0&amp;byline=0&amp;color=c8dd63"/>
<images>
<item lang="en" featured='yes' id="78" url="http://linkto-image-url.jpg"/>
<item lang="en" id="56" url="http://linkto-image-url.jpg"/>
<item lang="fr" id="78" url="http://linkto-image-url.jpg"/>
</images>
<categories>
<cat lang="en">11,8</cat>
<cat lang="fr">10,9</cat>
</categories>
<published order="20120813">13-08-2012</published>
</entry>
</projects>
</data>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:string="http://symphony-cms.com/functions"
xmlns:_string="http://symphony-cms.com/functions"
xmlns:func="http://exslt.org/functions" exlude-element-prefixes="func exsl _string string xsl"
xmlns:exsl="http://exslt.org/common" >
<xsl:import href="https://raw.github.com/gist/1415416/9d59f8ec14e6da049ac1683d5b76d2dbe184b057/String-Utilities.xsl"/>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
<xsl:variable name="lang" select="'en'"/>
<xsl:variable name="vDoc" select="/"/>
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet"><xsl:attribute name="url"><xsl:value-of select="//data/preferences/stylesheets/entry/url/@link"/></xsl:attribute></link>
</head>
<body>
<header>
<nav>
<ul>
<xsl:apply-templates select="data/preferences/navlinks/entry">
<xsl:sort select="position()" data-type="number" order="descending"/>
</xsl:apply-templates>
</ul>
</nav>
</header>
<section id="main">
<xsl:apply-templates select="data"/>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="data">
<hgroup><h1>
<xsl:value-of select="preferences/sitename" />
</h1>
</hgroup>
<ul id="lang-select">
<xsl:apply-templates select="preferences/languages/entry"/>
</ul>
<ul id="categories">
<xsl:apply-templates select="preferences/categories/entry"/>
</ul>
<section id="content">
<xsl:apply-templates select="projects/entry">
<xsl:sort select="published/@order" data-type="number" order="ascending"/>
</xsl:apply-templates>
</section>
</xsl:template>
<xsl:template match="preferences/languages/entry">
<li><a><xsl:attribute name="href">?lang=<xsl:value-of select="./@lang"/></xsl:attribute><xsl:value-of select="."/></a></li>
</xsl:template>
<xsl:template match="preferences/categories/entry">
<li><xsl:value-of select="cat[@lang = $lang]/."/></li>
</xsl:template>
<xsl:template match="data/preferences/categories/entry" mode="proj">
<li><xsl:value-of select="cat[@lang = $lang]/."/></li>
</xsl:template>
<xsl:template match="projects/entry">
<div>
<h1><xsl:value-of select="title[@lang = $lang]/."/></h1>
<h2>ID: <xsl:value-of select="@id"/></h2>
<xsl:apply-templates select="video"/>
<xsl:copy-of select="description[@lang = $lang]/*" />
<ul id="proj-cat">
<xsl:apply-templates select="categories" mode="in"/>
</ul>
</div>
</xsl:template>
<xsl:template match="video">
<iframe>
<xsl:attribute name="src"><xsl:value-of select="@url"/></xsl:attribute>
<xsl:attribute name="width">512</xsl:attribute>
<xsl:attribute name="height">288</xsl:attribute>
</iframe>
</xsl:template>
<xsl:template match="categories" mode="in">
<xsl:variable name="category" select="cat[@lang = $lang]/."/>
<xsl:variable name="catlist" select="string:split($category,',')"/>
<xsl:for-each select="exsl:node-set($catlist)/nodeset/node">
<xsl:variable name="splitResult" select="current()"/>
<li><xsl:value-of select="current()"/> - <xsl:copy-of select="$splitResult"/> - <xsl:copy-of select="//data/preferences/categories/entry[@id = '$splitResult']/cat[@lang=$lang]/."/></li>
</xsl:for-each>
<!--Stack Overflow Split String http://stackoverflow.com/questions/2850100/comma-separated-string-parsing-xslt -->
<!-- Explanation for accessing temp tree data http://stackoverflow.com/questions/3574483/why-cant-i-use-values-of-nodes-i-retrieve-by-using-exslnode-set-setdistinct-i -->
</xsl:template>
<xsl:template match="data/preferences/navlinks/entry">
<li><a><xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute><xsl:value-of select="title[@lang = $lang]/."/></a></li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment