1<?xml version="1.0"?> 2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 3 4 <xsl:output method="html" encoding="utf-8"/> 5 6 <xsl:template name="element"> 7 <xsl:param name="indent" select="0"/> 8 <xsl:text> 9</xsl:text> 10 <!-- this next one's a real kludge!! --> 11 <xsl:value-of select="substring (' ', 0, $indent * 3)"/> 12 <xsl:choose> 13 <xsl:when test="self::text()"> 14 <span class="text"> 15 <xsl:value-of select="normalize-space(.)"/> 16 </span> 17 </xsl:when> 18 <xsl:when test="self::*"> 19 <span class="element"> 20 <xsl:value-of select="concat('<',name(.),'>')"/> 21 </span> 22 <xsl:for-each select="node()"> 23 <xsl:call-template name="element"> 24 <xsl:with-param name="indent"> 25 <xsl:value-of select="$indent + 1"/> 26 </xsl:with-param> 27 </xsl:call-template> 28 </xsl:for-each> 29 <xsl:text> 30</xsl:text> 31 <xsl:value-of select="substring (' ', 0, $indent * 3)"/> 32 <span class="element"> 33 <xsl:value-of select="concat('</',name(.),'>')"/> 34 </span> 35 </xsl:when> 36 </xsl:choose> 37 </xsl:template> 38 39 40 <xsl:template match="/"> 41 <html> 42 <style> 43body { background-color: #ffffff; } 44.element { color: #447744; } 45.text { color: #774444; } 46 </style> 47 <body> 48 <pre> 49 <xsl:for-each select="node()"> 50 <xsl:call-template name="element"> 51 <xsl:with-param name="indent"> 52 1 53 </xsl:with-param> 54 </xsl:call-template> 55 </xsl:for-each> 56 </pre> 57 </body> 58 </html> 59 </xsl:template> 60 61</xsl:stylesheet> 62 63