Skip to content

Instantly share code, notes, and snippets.

@michael-e
Forked from nils-werner/master.xml
Created March 7, 2012 09:23
Show Gist options
  • Save michael-e/1992138 to your computer and use it in GitHub Desktop.
Save michael-e/1992138 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<link rel="stylesheet" href="workspace/assets/style.css"/>
</head>
<body>
<div id="head">
<h1>Title</h1>
</div>
<div id="package">
<div id="content">
<h2>Blog</h2>
<div datasource="blog-articles">
<div class="article">
<h3 value="title">Title</h3>
<p copy="body">
Lorem Ipsum
</p>
</div>
</div>
<div id="comments">
<h3>Comments</h3>
<div datasource="article-comments">
<p value="text">
Commenttext
</p>
</div>
</div>
<div id="sidebar">
<h3>
All Articles
</h3>
<ul>
<div datasource="blog-article-index">
<li value="title">Something</li>
</div>
</ul>
</div>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<x:stylesheet version="1.0"
xmlns:x="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias">
<x:output method="xml"
encoding="UTF-8"
indent="yes" />
<x:namespace-alias stylesheet-prefix="xsl" result-prefix="x"/>
<x:template match="*">
<x:element name="{name()}">
<x:apply-templates select="* | @* | text()" />
</x:element>
</x:template>
<x:template match="@*">
<x:attribute name="{name()}">
<x:value-of select="."/>
</x:attribute>
</x:template>
<x:template match="@datasource | @value | @copy" />
<x:template match="/">
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias">
<xsl:output method="xml"
encoding="UTF-8"
indent="yes" />
<x:apply-templates />
<x:apply-templates select="//*[@datasource]" mode="templates" />
</xsl:stylesheet>
</x:template>
<x:template match="*[@datasource]">
<xsl:apply-templates select="{@datasource}/entry" />
</x:template>
<x:template match="*[@value]/text()">
<xsl:value-of select="{../@value}" />
</x:template>
<x:template match="*[@copy]">
<xsl:copy-of select="{@copy}/*" />
</x:template>
<x:template match="*[@datasource]" mode="templates">
<x:text>
</x:text>
<xsl:template match="{@datasource}/entry">
<x:apply-templates />
</xsl:template>
</x:template>
</x:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment