Skip to content

Instantly share code, notes, and snippets.

@wallymathieu
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wallymathieu/8dcc3055b36422d3a504 to your computer and use it in GitHub Desktop.
Save wallymathieu/8dcc3055b36422d3a504 to your computer and use it in GitHub Desktop.
xml to html tables
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/TR/REC-html40" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--Licensed under the new BSD License.-->
<xsl:output encoding="utf-8" indent="yes" method="html" omit-xml-declaration="yes"/>
<xsl:template match="/">
<html>
<head>
<style type="text/css">table{
border-collapse: collapse;
border: 1px solid black;
}
table td{
border: 1px solid black;
}
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="node()">
<table>
<tr>
<th>
<xsl:value-of select="name()"/>
</th>
<!--</tr><tr>-->
<xsl:if test="@*">
<xsl:for-each select="@*">
<th>
<xsl:value-of select="name()"/>
</th>
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</xsl:if>
<xsl:if test="node()">
<td>
<xsl:for-each select="node()">
<xsl:apply-templates select="."/>
</xsl:for-each>
</td>
</xsl:if>
</tr>
</table>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment