Skip to content

Instantly share code, notes, and snippets.

@allen
Forked from andrewminton/master.xml
Created October 26, 2012 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allen/3956567 to your computer and use it in GitHub Desktop.
Save allen/3956567 to your computer and use it in GitHub Desktop.
<data>
<remote>
<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>
<title lang="en" url="http://domain.co.uk/en/home">Home</title>
<title lang="fr" url="http://domain.co.uk/fr/home">Home</title>
</entry>
<entry>
<title lang="en" url="http://domain.co.uk/en/projects">Projects</title>
<title lang="fr" url="http://domain.co.uk/fr/projet">Projet</title>
</entry>
<entry>
<title lang="en" url="http://domain.co.uk/en/contact">Contact</title>
<title lang="fr" url="http://domain.co.uk/fr/contacte">Contacte</title>
</entry>
<entry>
<title lang="en" url="http://domain.co.uk/en/about">About</title>
<title lang="fr" url="http://domain.co.uk/fr/about">Vous</title>
</entry>
<entry>
<title lang="en" url="http://domain.co.uk/en/portfolio">Portfolio</title>
<title lang="fr" url="http://domain.co.uk/fr/portfolio">Folio</title>
</entry>
</navlinks>
<categories>
<entry id="9">
<cat lang="en" handle="construction">Commodity</cat>
<cat lang="fr" handle="construcion">Commodity</cat>
</entry>
<entry id="10">
<cat lang="en" handle="client">Client</cat>
<cat lang="fr" handle="cliente">Cliente</cat>
</entry>
<entry id="11">
<cat lang="en" handle="country">Country</cat>
<cat lang="fr" handle="country">Country</cat>
</entry>
<entry id="8">
<cat lang="en" handle="mandate">Mandate</cat>
<cat lang="fr" handle="mandate">Mandate</cat>
</entry>
</categories>
</preferences>
<projects>
<entry id="2" sort-order="0">
<title lang="en" handle="project-title">Project title</title>
<title lang="fr" handle="titre-du-projet">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>
</remote>
</data>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:func="http://exslt.org/functions"
extension-element-prefixes="func exsl str xsl"
exlude-element-prefixes="func exsl str xsl"
xmlns:exsl="http://exslt.org/common">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes" />
<xsl:variable name="vDoc" select="/"/>
<xsl:variable name="url-cat" select="'construction'"/>
<xsl:variable name="url-language" select="'en'"/>
<xsl:variable name="root" select="'http://localhost:8080'"/>
<xsl:variable name="current-page" select="'portfolio'"/>
<xsl:variable name="title" select="''"/>
<xsl:variable name="category">
<xsl:value-of select="/data/remote/data/preferences/categories/entry/cat[@lang = $url-language and @handle = $url-cat]/../@id"/>
</xsl:variable>
<xsl:variable name="projectID">
<xsl:value-of select="/data/remote/data/projects/entry/title[@handle = /data/params/title]/../@id"/>
</xsl:variable>
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" url="{data/remote/data/preferences/stylesheets/entry/url/@link}"/>
</head>
<body>
<header>
<nav>
<ul>
<xsl:apply-templates select="data/remote/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/remote/data"/>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="data/remote/data">
<hgroup>
<h1>
<xsl:value-of select="preferences/sitename"/> - <xsl:value-of select="$category"/>
</h1>
</hgroup>
<ul id="lang-select">
<xsl:apply-templates select="preferences/languages/entry"/>
</ul>
<aside>
<ul id="categories">
<xsl:apply-templates select="preferences/categories/entry"/>
</ul>
</aside>
<section id="content">
<xsl:choose>
<xsl:when test="$title !=''">
<xsl:apply-templates select="projects/entry[@id = $projectID]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="projects/entry[contains(concat(',', categories/cat, ','), concat(',', $category, ','))]">
<xsl:sort select="published/@order" data-type="number" order="ascending"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</section>
</xsl:template>
<xsl:template match="preferences/languages/entry">
<li>
<a href="{concat($root,'/',./@lang,'/',$current-page)}">
<xsl:value-of select="."/>
</a>
</li>
</xsl:template>
<xsl:template match="preferences/categories/entry">
<li>
<a href="?cat={cat[@lang = $url-language]/@handle}">
<xsl:value-of select="cat[@lang = $url-language]/."/>
</a>
</li>
</xsl:template>
<xsl:template match="data/remote/data/preferences/categories/entry" mode="proj">
<li><xsl:value-of select="cat[@lang = $url-language]/."/></li>
</xsl:template>
<xsl:template match="projects/entry">
<article id="{position()}">
<hgroup>
<h1><xsl:value-of select="title[@lang = $url-language]/."/></h1>
<h2>ID: <xsl:value-of select="@id"/></h2>
<h3><xsl:apply-templates select="categories" mode="id"/></h3>
</hgroup>
<xsl:apply-templates select="video"/>
<xsl:copy-of select="description[@lang = $url-language]/*"/>
<footer>
<ul id="proj-cat">
<xsl:apply-templates select="categories" mode="in"/>
</ul>
</footer>
</article>
</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 = $url-language]/."/>
<xsl:variable name="catlist" select="str:split($category,',')"/>
<xsl:variable name="catID" select="exsl:node-set($catlist)/nodeset/node"/>
<xsl:for-each select="//data/remote/data/preferences/categories/entry">
<xsl:if test="@id = $catID">
<li><xsl:value-of select="cat[@lang=$url-language]/."/></li>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="categories" mode="id">
<xsl:variable name="category" select="cat[@lang = $url-language]/."/>
<xsl:value-of select="$category"/>
</xsl:template>
<xsl:template match="data/remote/data/preferences/navlinks/entry">
<li>
<a href="{title[@lang = $url-language]/@url}">
<xsl:value-of select="title[@lang = $url-language]/."/>
</a>
</li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment