Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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