Skip to content

Instantly share code, notes, and snippets.

@carols10cents
Created October 14, 2016 21:12
Show Gist options
  • Save carols10cents/cd58372b3ad460c32203e5abc2d32f21 to your computer and use it in GitHub Desktop.
Save carols10cents/cd58372b3ad460c32203e5abc2d32f21 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<doc>
<album>
<title>Thriller</title>
<artist>Michael Jackson</artist>
</album>
<book>
<title>Little Women</title>
<author>Louisa May Alcott</author>
</book>
<album>
<title>Live Rust</title>
<artist>Neil Young</artist>
</album>
</doc>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>Title</th>
<th>Creator</th>
<th>Favorite?</th>
</tr>
<xsl:apply-templates select="*" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="album[contains(title, 'Rust')]">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
<td>YES</td>
</tr>
</xsl:template>
<xsl:template match="album">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
<td />
</tr>
</xsl:template>
<xsl:template match="book">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="author" /></td>
<td />
</tr>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment