<?xml version='1.0' encoding='ISO-8859-1'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<!-- The main template. Builds a basic html Skeleton and calls the rest -->
<xsl:template match="/">
<html>
<head>
<title>Highlighted xsl Code</title>
</head>
<body bgcolor="#ffffff">
<pre>
<xsl:apply-templates select="*|text()|comment()|processing-instruction()"/>
</pre>
</body>
</html>
</xsl:template>


<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="comment()">
<xsl:text>&lt;!--</xsl:text>
<xsl:element name="i">
<xsl:value-of select="."/>
</xsl:element>
<xsl:text>--&gt;</xsl:text>
</xsl:template>

<xsl:template match="processing-instruction()">
<font color="red"><i><xsl:value-of select="."/></i></font>
</xsl:template>

<xsl:template match="*">
<xsl:choose>
<xsl:when test="*|text()|comment()|processing-instruction()"><xsl:call-template name="notempty"/></xsl:when>
<xsl:otherwise><xsl:call-template name="empty"/></xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="notempty">
<xsl:choose>
<xsl:when test="substring(name(.),1,3)='xsl'">
<xsl:element name="b">
<xsl:text>&lt;</xsl:text>
<xsl:element name="font">
<xsl:attribute name="color">blue</xsl:attribute>
<xsl:value-of select="name(.)"/>
</xsl:element>
</xsl:element>
<xsl:call-template name="stylesheedattributes"/>
<xsl:element name="b"> 
<xsl:text>&gt;</xsl:text>
</xsl:element>
<xsl:apply-templates/>
<xsl:element name="b"> 
<xsl:text>&lt;/</xsl:text>
<xsl:element name="font">
<xsl:attribute name="color">blue</xsl:attribute>
<xsl:value-of select="name(.)"/>
</xsl:element>
<xsl:text>&gt;</xsl:text>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:call-template name="attributes"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates/>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text>&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="empty">
<xsl:choose>
<xsl:when test="substring(name(.),1,3)='xsl'">
<xsl:element name="b">
<xsl:text>&lt;</xsl:text>
<xsl:element name="font">
<xsl:attribute name="color">blue</xsl:attribute>
<xsl:value-of select="name(.)"/>
</xsl:element>
</xsl:element>
<xsl:call-template name="stylesheedattributes"/>
<xsl:element name="b">
<xsl:text>/&gt;</xsl:text>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:call-template name="attributes"/>
<xsl:text>/&gt;</xsl:text>
</xsl therwise>
</xsl:choose>
</xsl:template>

<xsl:template name="stylesheedattributes">
<xsl:for-each select="attribute::*">
<xsl:text> </xsl:text>
<xsl:element name="b">
<xsl:value-of select="name(.)"/>
</xsl:element>
<xsl:text>="</xsl:text>
<xsl:element name="font">
<xsl:attribute name="color">blue</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
<xsl:text>"</xsl:text>
</xsl:for-each>
</xsl:template>

<xsl:template name="attributes">
<xsl:for-each select="attribute::*">
<xsl:text> </xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

