joerg 2004/05/01 06:20:56
Modified: src/webapp/stylesheets/system xml2html.xslt Log: added namespace functionality provided by Andrew Thornton (http://marc.theaimsgroup.com/?t=108307357600006&r=1&w=4), cleaned up some useless xsl:text, removed one useless template (match="*[*]" was exactly the same like match="*[node()]"), fixed monospace-style Revision Changes Path 1.10 +49 -61 cocoon-2.1/src/webapp/stylesheets/system/xml2html.xslt Index: xml2html.xslt =================================================================== RCS file: /home/cvs/cocoon-2.1/src/webapp/stylesheets/system/xml2html.xslt,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- xml2html.xslt 6 Mar 2004 13:42:12 -0000 1.9 +++ xml2html.xslt 1 May 2004 13:20:55 -0000 1.10 @@ -40,8 +40,8 @@ <xsl:template name="head"> <HEAD> <STYLE> - BODY {background-color: white; color: black; font: monospace;} - .b {cursor:pointer; color:red; font-weight:bold; text-decoration:none} + BODY {background-color: white; color: black; font-family: monospace;} + .b {cursor:pointer; color:red; font-weight:bold; text-decoration:none; padding-right: 2px;} .e {border: 0px; padding: 0px; margin: 0px 0px 0px 2em; text-indent:-1em;} .en {color:#000088; font-weight:bold;} .an {color:#880000} @@ -96,17 +96,13 @@ <!-- match processing instructions --> <xsl:template match="processing-instruction()"> <DIV class="e"> - <SPAN class="m"> - <xsl:text><?</xsl:text> - </SPAN> + <SPAN class="m"><?</SPAN> <SPAN class="pi"> <xsl:value-of select="name(.)"/> <xsl:text> </xsl:text> <xsl:value-of select="."/> </SPAN> - <SPAN class="m"> - <xsl:text>?></xsl:text> - </SPAN> + <SPAN class="m">?></SPAN> </DIV> </xsl:template> @@ -123,17 +119,13 @@ <xsl:template match="comment()"> <DIV class="e"> <SPAN class="b" onclick="click(event)">-</SPAN> - <SPAN class="m"> - <xsl:text><!--</xsl:text> - </SPAN> + <SPAN class="m"><!--</SPAN> <SPAN class="c"> <PRE> <xsl:value-of select="."/> </PRE> </SPAN> - <SPAN class="m"> - <xsl:text>--></xsl:text> - </SPAN> + <SPAN class="m">--></SPAN> </DIV> </xsl:template> @@ -152,8 +144,8 @@ </xsl:if> </xsl:template> - <!-- match empty nodes --> - <xsl:template match="*"> + <!-- match empty elements --> + <xsl:template match="*[not(node())]"> <DIV class="e"> <SPAN class="m"><</SPAN> <SPAN class="en"> @@ -163,50 +155,15 @@ <xsl:text> </xsl:text> </xsl:if> <xsl:apply-templates select="@*"/> - <SPAN class="m"> - <xsl:text>/></xsl:text> - </SPAN> - </DIV> - </xsl:template> - - <xsl:template match="*[node()]"> - <DIV class="e"> - <DIV> - <SPAN class="b" onclick="click(event)">-</SPAN> - <SPAN class="m"><</SPAN> - <SPAN class="en"> - <xsl:value-of select="name(.)"/> - </SPAN> - <xsl:if test="@*"> - <xsl:text> </xsl:text> - </xsl:if> - <xsl:apply-templates select="@*"/> - <SPAN class="m"> - <xsl:text>></xsl:text> - </SPAN> - </DIV> - <DIV> - <xsl:apply-templates/> - <DIV> - <SPAN class="m"> - <xsl:text></</xsl:text> - </SPAN> - <SPAN class="en"> - <xsl:value-of select="name(.)"/> - </SPAN> - <SPAN class="m"> - <xsl:text>></xsl:text> - </SPAN> - </DIV> - </DIV> + <xsl:apply-templates select="." mode="namespace"/> + <SPAN class="m">/></SPAN> </DIV> </xsl:template> - <xsl:template match="*[text() and not (comment() or processing-instruction())]"> + <!-- match elements with only text(), they are not closeable --> + <xsl:template match="*[text()][not(* or comment() or processing-instruction())]" priority="10"> <DIV class="e"> - <SPAN class="m"> - <xsl:text><</xsl:text> - </SPAN> + <SPAN class="m"><</SPAN> <SPAN class="en"> <xsl:value-of select="name(.)"/> </SPAN> @@ -214,6 +171,7 @@ <xsl:text> </xsl:text> </xsl:if> <xsl:apply-templates select="@*"/> + <xsl:apply-templates select="." mode="namespace"/> <SPAN class="m"> <xsl:text>></xsl:text> </SPAN> @@ -230,7 +188,7 @@ </DIV> </xsl:template> - <xsl:template match="*[*]" priority="20"> + <xsl:template match="*[node()]"> <DIV class="e"> <DIV> <SPAN class="b" onclick="click(event)">-</SPAN> @@ -242,6 +200,7 @@ <xsl:text> </xsl:text> </xsl:if> <xsl:apply-templates select="@*"/> + <xsl:apply-templates select="." mode="namespace"/> <SPAN class="m"> <xsl:text>></xsl:text> </SPAN> @@ -249,9 +208,7 @@ <DIV> <xsl:apply-templates/> <DIV> - <SPAN class="m"> - <xsl:text></</xsl:text> - </SPAN> + <SPAN class="m"></</SPAN> <SPAN class="en"> <xsl:value-of select="name(.)"/> </SPAN> @@ -261,6 +218,37 @@ </DIV> </DIV> </DIV> + </xsl:template> + + <xsl:template match="*" mode="namespace"> + <xsl:variable name="context" select="."/> + <xsl:for-each select="namespace::node()"> + <xsl:variable name="nsuri" select="."/> + <xsl:variable name="nsprefix" select="name()"/> + <xsl:choose> + <xsl:when test="$nsprefix = 'xml'"> + <!-- xml namespace --> + </xsl:when> + <xsl:when test="$context/../namespace::node()[name() = $nsprefix and . = $nsuri]"> + <!-- namespace already declared on the parent --> + </xsl:when> + <xsl:otherwise> + <xsl:text> </xsl:text> + <SPAN class="an"> + <xsl:text>xmlns</xsl:text> + <xsl:if test="$nsprefix"> + <xsl:text>:</xsl:text> + <xsl:value-of select="$nsprefix"/> + </xsl:if> + </SPAN> + <SPAN class="m">="</SPAN> + <SPAN class="av"> + <xsl:value-of select="."/> + </SPAN> + <SPAN class="m">"</SPAN> + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> </xsl:template> </xsl:stylesheet>
