Created
September 17, 2010 19:59
-
-
Save 0mg/584832 to your computer and use it in GitHub Desktop.
XMLStyle.XSLT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0"?> | |
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | |
| <xsl:template match="/"> | |
| <root> | |
| <style xmlns="http://www.w3.org/1999/xhtml"> | |
| root { | |
| font-family: monospace; | |
| } | |
| element, char, comment, proc { | |
| display: block; | |
| margin-left: 2ex; | |
| } | |
| tag name, attr name, proc name { | |
| color: blue; | |
| } | |
| attr value, proc value { | |
| color: green; | |
| } | |
| char { | |
| color: red; | |
| } | |
| comment value { | |
| color: silver; | |
| } | |
| </style> | |
| <xsl:call-template name="main"/> | |
| </root> | |
| </xsl:template> | |
| <xsl:template name="main"> | |
| <xsl:for-each select="node()"> | |
| <xsl:choose> | |
| <xsl:when test=".=self::processing-instruction()"> | |
| <proc><tag><?<name><xsl:value-of select="name()"/></name><xsl:value-of select="' '"/><value><xsl:value-of select="."/></value>?></tag></proc> | |
| </xsl:when> | |
| <xsl:when test=".=self::*"> | |
| <element> | |
| <xsl:choose> | |
| <xsl:when test="node()"> | |
| <tag><<name><xsl:value-of select="name()"/></name><xsl:call-template name="attr"/>></tag> | |
| <xsl:call-template name="main"/> | |
| <tag></<name><xsl:value-of select="name()"/></name>></tag> | |
| </xsl:when> | |
| <xsl:when test="not(node())"> | |
| <tag><<name><xsl:value-of select="name()"/></name><xsl:call-template name="attr"/>/></tag> | |
| </xsl:when> | |
| </xsl:choose> | |
| </element> | |
| </xsl:when> | |
| <xsl:when test=".=self::text()"> | |
| <char><xsl:value-of select="."/></char> | |
| </xsl:when> | |
| <xsl:when test=".=self::comment()"> | |
| <comment><tag><!--</tag><value><xsl:value-of select="."/></value><tag>--></tag></comment> | |
| </xsl:when> | |
| </xsl:choose> | |
| </xsl:for-each> | |
| </xsl:template> | |
| <xsl:template name="attr"> | |
| <xsl:for-each select="@*"> | |
| <xsl:value-of select="' '"/><attr><name><xsl:value-of select="name()"/></name>="<value><xsl:value-of select="."/></value>"</attr> | |
| </xsl:for-each> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment