Skip to content

Instantly share code, notes, and snippets.

@pjmagee
Created November 29, 2012 18:48
Show Gist options
  • Select an option

  • Save pjmagee/4171074 to your computer and use it in GitHub Desktop.

Select an option

Save pjmagee/4171074 to your computer and use it in GitHub Desktop.
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:math="http://www.exslt.org/math">
<xsl:output method="html" version="4.0"/>
<xsl:template match="/">
<!-- XSLT and Literal Result Elements -->
<html>
<head>
<title>Lecturers</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Lecturers</h1>
<table border="1">
<thead>
<tr>
<th>Title</th>
<th>Name</th>
<th>Teaching</th>
<th>Research</th>
</tr>
</thead>
<tbody>
<!-- XSL FOR EACH -->
<xsl:for-each select="lecturers">
<!-- LECTURER TEMPLATE -->
<xsl:apply-templates select="lecturer">
<!-- XSL SORT -->
<xsl:sort select="name/@last" order="ascending" />
</xsl:apply-templates>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
<!-- LECTURER TEMPLATE -->
<xsl:template match="lecturer">
<xsl:variable name="noResearch">
<xsl:text>This lecturer does not like researching. He fails in life.</xsl:text>
</xsl:variable>
<tr>
<td style="text-align: center;"> <!-- TITLE -->
<xsl:value-of select="name/@title" />
</td>
<td style="text-align: center;"> <!-- NAME -->
<xsl:value-of select="name/@first"/><xsl:text> </xsl:text>
<xsl:value-of select="name/@last" />
</td>
<td> <!-- TEACHING -->
<ul>
<xsl:for-each select="teaching">
<xsl:apply-templates select="course">
<!-- XPATH SUBSTRING -->
<xsl:sort select="substring(@code, 3)" data-type="number" order="descending" /> <!-- descending | ascending -->
</xsl:apply-templates>
</xsl:for-each>
</ul>
</td>
<td> <!-- RESEARCH -->
<xsl:choose>
<xsl:when test="research = 'None'">
<!-- <xsl:copy-of select="$noResearch" /> -->
<xsl:value-of select="$noResearch" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="research" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
<!-- COURSE TEMPLATE -->
<xsl:template match="course">
<!-- <li> -->
<xsl:value-of select="position()" /><xsl:text> - </xsl:text>
<xsl:value-of select="concat(., ' (', @code, ') ')" /> <!-- XPATH FUNC -->
<br />
<!-- </li> -->
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment