Skip to content

Instantly share code, notes, and snippets.

@mjbommar
Created August 14, 2011 16:50
Show Gist options
  • Save mjbommar/1145065 to your computer and use it in GitHub Desktop.
Save mjbommar/1145065 to your computer and use it in GitHub Desktop.
XSL stylesheet for Michigan Compiled Law XML
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/code">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Michigan Compiled Law</title>
<style type="text/css">
.chapter {
margin-left:10px;
}
.statute {
margin-left:20px;
}
.division {
margin-left:30px;
}
.section {
margin-left:40px;
padding:8px;
border-bottom:1px solid #999;
margin-bottom:4px;
background-color:#eec;
}
</style>
</head>
<body>
<h1>Michigan Compiled Law</h1>
<div>Date: August 4, 2011</div>
<h1>Table of Contents</h1>
<ol>
<xsl:for-each select="chapter">
<li>
<a>
<xsl:attribute name="href">#<xsl:value-of select="@id" /></xsl:attribute>
<xsl:value-of select="@name" /> - <xsl:value-of select="@description" />
</a>
</li>
<ol>
<xsl:for-each select="statute">
<li>
<a>
<xsl:attribute name="href">#<xsl:value-of select="@id" /></xsl:attribute>
<xsl:value-of select="@name" /> - <xsl:value-of select="@description" />
</a>
</li>
</xsl:for-each>
</ol>
</xsl:for-each>
</ol>
<xsl:for-each select="chapter">
<h2>
<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="class">chapter</xsl:attribute>
<xsl:value-of select="@name" /> - <xsl:value-of select="@description" />
</h2>
<xsl:for-each select="statute">
<h3>
<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="class">statute</xsl:attribute>
<xsl:variable name="repeal_string" select="'Repeal'" />
<xsl:variable name="desc_string" select="@description" />
<xsl:if test="starts-with($desc_string, $repeal_string)">
<xsl:attribute name="style">color: red;</xsl:attribute>
</xsl:if>
<xsl:value-of select="@name" />
-
<xsl:value-of select="@description" />
</h3>
<xsl:apply-templates />
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="cite">
<a>
<xsl:attribute name="href">#<xsl:value-of select="@target" /></xsl:attribute>
<xsl:value-of select="." />
</a>
</xsl:template>
<xsl:template match="section">
<div>
<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="class">section</xsl:attribute>
<p>
<em>
<xsl:value-of select="@name" />
-
<xsl:value-of select="@description" />
</em>
</p>
<xsl:for-each select="p">
<p>
<xsl:apply-templates />
</p>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="division">
<h4>
<xsl:attribute name="id"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@id" /></xsl:attribute>
<xsl:attribute name="class">division</xsl:attribute>
<xsl:variable name="repeal_string" select="'Repeal'" />
<xsl:variable name="desc_string" select="@description" />
<xsl:if test="starts-with($desc_string, $repeal_string)">
<xsl:attribute name="style">color: red;</xsl:attribute>
</xsl:if>
<xsl:value-of select="@name" />
-
<xsl:value-of select="@description" />
</h4>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment