Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Created March 14, 2012 11:41
Show Gist options
  • Save andrewminton/2035945 to your computer and use it in GitHub Desktop.
Save andrewminton/2035945 to your computer and use it in GitHub Desktop.
<data>
<page-title>This is a H1 tag</page-title>
<page-content id="82">
<h2>The Gorilla Team</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ac metus non ante sodales vulputate. Cras porttitor vestibulum varius. Maecenas tristique tortor id nulla gravida venenatis. Integer dapibus, sapien vitae aliquam laoreet, libero massa elementum ante, eu pulvinar erat odio vel augue. Nulla facilisi. Praesent vestibulum bibendum metus.</p>
</page-content>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="data">
<xsl:apply-templates select="data" mode="html"/>
</xsl:template>
<xsl:template match="data">
<h1 class="page_title"><xsl:value-of select="page-title"/></h1>
<xsl:apply-templates select="page-content//*" mode="html"/>
</xsl:template>
<xsl:template match="*" mode="html">
<xsl:element name="{name()}">
<xsl:apply-templates select="* | @* | text()" mode="html"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*" mode="html">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="h2" mode="html">
<xsl:element name="h2">
<xsl:apply-templates select="* | @* | text()"/>
</xsl:element>
<xsl:if test="name(preceding-sibling::*[last()])='h1'">
<xsl:attribute name="class">follows h1</xsl:attribute>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment