Skip to content

Instantly share code, notes, and snippets.

@nilshoerrmann
Forked from andrewminton/master.xml
Created March 14, 2012 17:55
Show Gist options
  • Save nilshoerrmann/2038224 to your computer and use it in GitHub Desktop.
Save nilshoerrmann/2038224 to your computer and use it in GitHub Desktop.
<data>
<page-content id="82">
<h1>This is a H1</h1>
<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>
<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>
<h2>This is another h2 I don't want affected</h2>
</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="/">
<xsl:apply-templates select="/data/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" priority="1">
<h2>
<xsl:if test="name(preceding-sibling::*[last()]) = 'h1'">
<xsl:attribute name="class">sub-title</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="* | text()" mode="html"/>
</h2>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment