Skip to content

Instantly share code, notes, and snippets.

@spdustin
Created October 29, 2012 19:18
Show Gist options
  • Save spdustin/3975862 to your computer and use it in GitHub Desktop.
Save spdustin/3975862 to your computer and use it in GitHub Desktop.
XSL - test for empty and create UL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<table>
<thead>
<tr>
<th>Make</th>
<th>Model</th>
<th>Passengers</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates />
</tbody>
</table>
</xsl:template>
<xsl:template match="/cars/car">
<tr>
<td><xsl:value-of select="@make" /></td>
<td><xsl:value-of select="@model" /></td>
<td>
<xsl:if test="passenger">
<ul>
<xsl:apply-templates />
</ul>
</xsl:if>
</td>
</tr>
</xsl:template>
<xsl:template match="passenger">
<li><xsl:value-of select="@name" /></li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment