Subject: RE: [xsl] msxml default stylesheet - now in XSLT From: "Trace Wilson" <trace_wilson@xxxxxxxxx> Date: Tue, 22 May 2001 13:34:14 +1000 |
If you do not want a DHTML version, please give this script a try, that was originally written by Jason Patterson at SnippetCentral at http://www.vbxml.com/snippetcentral/main.asp?view=viewsnippet&lang=&id=v2001 0305161458 Its great for documenting your code. You need to insert your XSL as your XML code in which ever transforming tool you are using. The output is a replica of what is in your XSLT but written in HTML. You can change the colour output by changing the parameters passed into the formatXML template. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" method="xml"/> <xsl:param name="includexml" select="'yes'" /> <xsl:template match="/"> <blockquote> <xsl:if test="$includexml = 'yes'"> <font style="color:green;font:10pt 'Verdana';"> <xsl:text><?xml version="1.0"?></xsl:text> </font> </xsl:if> <xsl:for-each select="node()"> <xsl:call-template name="formatxml"> <xsl:with-param name="selnode" select="."/> </xsl:call-template> </xsl:for-each> </blockquote> </xsl:template> <xsl:template name="formatxml"> <xsl:param name="selnode"/> <xsl:param name="template-style">font:10pt 'Verdana';</xsl:param> <xsl:param name="indent">0em;</xsl:param> <xsl:param name="punctuation-style">color:blue;</xsl:param> <xsl:param name="node-name-style">color:#990000;</xsl:param> <xsl:param name="comment-style">color:gray;</xsl:param> <xsl:param name="pi-style">color:green;</xsl:param> <xsl:param name="attr-value-style">color:black;</xsl:param> <xsl:param name="attr-name-style">color:red</xsl:param> <div> <xsl:choose> <xsl:when test="self::comment()"> <xsl:attribute name="style"><xsl:text>padding-left:</xsl:text><xsl:value-of select="$indent"/></xsl:attribute> <font style="{$template-style}{$comment-style}"> <xsl:text><!--</xsl:text> <xsl:value-of select="$selnode"/> <xsl:text>></xsl:text> </font> </xsl:when> <xsl:when test="self::processing-instruction()"> <xsl:attribute name="style"><xsl:text>padding-left:</xsl:text><xsl:value-of select="$indent"/></xsl:attribute> <font style="{$template-style}{$pi-style}"> <xsl:text><?</xsl:text> <xsl:value-of select="name()"/> <xsl:text/> <xsl:value-of select="."/> <xsl:text>?></xsl:text> </font> </xsl:when> <xsl:when test="self::text()"> <xsl:attribute name="style"><xsl:text>display:inline;</xsl:text></xsl:attribute> <font style="{$template-style}{text-node-style}"> <xsl:call-template name="html-replace-entities"> <xsl:with-param name="text" select="$selnode"/> </xsl:call-template> </font> </xsl:when> <xsl:otherwise> <xsl:attribute name="style"><xsl:text>padding-left:</xsl:text><xsl:value-of select="$indent"/></xsl:attribute> <font style="{$template-style}{$punctuation-style}"> <xsl:text><</xsl:text> </font> <font style="{$template-style}{$node-name-style}"> <xsl:value-of select="name($selnode)"/> <xsl:for-each select="$selnode/@*"> <xsl:text> </xsl:text> <font style="{$template-style}{$attr-name-style}"> <xsl:value-of select="name()"/> </font> <font style="{$template-style}{$punctuation-style}"> <xsl:text>="</xsl:text> </font> <font style="{$template-style}{$attr-value-style}"> <xsl:value-of select="."/> </font> <font style="{$template-style}{$punctuation-style}"> <xsl:text>"</xsl:text> </font> </xsl:for-each> </font> <xsl:choose> <xsl:when test="count(node()) = 0"> <font style="{$template-style}{$punctuation-style}"> <xsl:text>/></xsl:text> </font> </xsl:when> <xsl:otherwise> <font style="{$template-style}{$punctuation-style}"> <xsl:text>></xsl:text> </font> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> <xsl:for-each select="$selnode/node()"> <xsl:call-template name="formatxml"> <xsl:with-param name="selnode" select="."/> <xsl:with-param name="indent" select="concat(number('2'),'em;')"/> </xsl:call-template> </xsl:for-each> <xsl:choose> <xsl:when test="self::text()"/> <xsl:when test="count(node()) = 0"/> <xsl:otherwise> <font style="{$template-style}{$punctuation-style}"> <xsl:text></</xsl:text> </font> <font style="{$template-style}{$node-name-style}"> <xsl:value-of select="name($selnode)"/> </font> <font style="{$template-style}{$punctuation-style}"> <xsl:text>></xsl:text> </font> </xsl:otherwise> </xsl:choose> </div> </xsl:template> <xsl:template name="html-replace-entities"> <xsl:param name="text"/> <xsl:variable name="tmp"> <xsl:call-template name="replace-substring"> <xsl:with-param name="from" select="'>'"/> <xsl:with-param name="to" select="'&gt;'"/> <xsl:with-param name="value"> <xsl:call-template name="replace-substring"> <xsl:with-param name="from" select="'<'"/> <xsl:with-param name="to" select="'&lt;'"/> <xsl:with-param name="value"> <xsl:call-template name="replace-substring"> <xsl:with-param name="from" select="'"'"/> <xsl:with-param name="to" select="'&quot;'"/> <xsl:with-param name="value"> <xsl:call-template name="replace-substring"> <xsl:with-param name="from" select="concat('&','apos;')"/> <xsl:with-param name="to" select="'&apos;'"/> <xsl:with-param name="value"> <xsl:call-template name="replace-substring"> <xsl:with-param name="from" select="'&'"/> <xsl:with-param name="to" select="'&amp;'"/> <xsl:with-param name="value" select="$text"/> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:with-param> </xsl:call-template> </xsl:variable> <xsl:value-of select="$tmp"/> </xsl:template> <xsl:template name="replace-substring"> <xsl:param name="value"/> <xsl:param name="from"/> <xsl:param name="to"/> <xsl:choose> <xsl:when test="contains($value,$from)"> <xsl:value-of select="substring-before($value,$from)"/> <xsl:value-of select="$to"/> <xsl:call-template name="replace-substring"> <xsl:with-param name="value" select="substring-after($value,$from)"/> <xsl:with-param name="from" select="$from"/> <xsl:with-param name="to" select="$to"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$value"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> HTH, Cheers, Trace Wilson http://www.vbxml.com For live-instructor lead XSLT online training, go to http://www.trainit.com Next course: May 29, 2001 GMT 8pm / US-ET 3pm May 30, 2001 GMT 10am /US-ET 5am _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] msxml default stylesheet - no, Nate Austin | Thread | [xsl] Re: msxml default stylesheet , Dimitre Novatchev |
RE: [xsl] regexp? or find # of "."s, Anthony E. | Date | [xsl] Re: unable to dynamically set, Dimitre Novatchev |
Month |