RE: [xsl] hard core xlt ;-)

Subject: RE: [xsl] hard core xlt ;-)
From: "Dylan Walsh" <Dylan.Walsh@xxxxxxxxxx>
Date: Thu, 26 Jul 2001 17:53:18 +0100
From:	Elise D. [SMTP:tyris_azriel@xxxxxxxx]
Sent:	Thursday, July 26, 2001 4:14 PM
To:	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:	RE: [xsl] hard core xlt ;-)

>well, i like the way you think about what is hard or
>not. i tryed for a first time to make "generic" xsl,
>meaning i never use the name of a tag, but only for a
>defined hierarchy/structure of the xml.
>so if i've well understood the way it should be done,
>i should detect the type of the node, detect what it
>contains .... is it right ?
>well, if you ever have a small example of doing this,
>it would be great :-)

The following probably has bugs, and it was written a long time ago. I'd
probably do a lot of things differently today, but I don't see any point
updating this when there is atleast one working implementation out

Microsoft have something similar in IE5, but that is MSXSL rather than
true XSLT. Their one is a lot slicker than mine. There are things you
cannot do in XSLT, but you can in MSXSL, in particular you cannot "see"
the XML declaration with XSLT. Microsoft may have updated that
transformation to proper XSLT for MSXML3, others on the list would know
more about that than me.

<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#160;">]> 
<xsl:stylesheet version="1.0" 
<xsl:output method="html" indent="yes" omit-xml-declaration="no"/>
<xsl:strip-space elements="*"/>

8/Dec/1999 DW

Comments are
now surrounded by PRE tags - preserves whitespace, but puts in a lot of
blank lines above
and below the comment

When script done, remove all whitespace (including carriage returns)
between the attributes 
part of the * template and the closing > of the opening tag a few lines
below (just after 
xsl:choose). Code will be one long line & harder to read, but it will no
longer put a space 
between the last attribute value and the right angle bracket.

Does weird stuff when DOCTYPE is present. Try it with a WML doc, seems
to go and get 
the external DTD and then displays the comments.


<!-- Root node -->
  <xsl:template match="/">
    <TITLE>XML file</TITLE>
        		You browser does not appear to support
JavaScript. To view this page properly, you must have JavaScript

  	&lt;!-- Hide this script from browsers which do not support it.
    		function moreInfo(arg) {
  		//  --&gt;

	<I><FONT COLOR="888888">(View the source for any XML, doctype,
or namespace declarations)</FONT></I><br/><br/>

    <FONT FACE="Arial,Helvetica" SIZE="2">
	<xsl:for-each select="attribute::*"> 
		<FONT COLOR="008800"><xsl:value-of
select="name()"/></FONT>=&quot;<FONT COLOR="0000FF"><B><xsl:value-of

	<xsl:apply-templates />

  <!-- All other elements -->
  <xsl:template match="*">
 	<!-- Start the opening tag, insert its name-->

	<!-- Create whitespace for every ancestor of node (indentation)
	<xsl:for-each select="ancestor::*">&nbsp; &nbsp; &nbsp;
	&lt;<FONT COLOR="880000"><xsl:value-of select="name()"/></FONT>

	<xsl:variable name="ANCESTORS"><xsl:for-each
select="name()"/>[<xsl:value-of select="generate-id()"/>]
	<xsl:variable name="PARENTNAME"><xsl:value-of

	<!-- If the tag has attributes, insert whitespace between
element name and first attribute name-->
	<xsl:if test="self::*[attribute::*]"><FONT>&nbsp;

 	<!-- Insert the attributes and their values-->
	<xsl:for-each select="attribute::*"> 
		<FONT COLOR="008800"><xsl:value-of
select="name()"/></FONT>=&quot;<FONT COLOR="0000FF"><B><A NAME=""
onclick="moreInfo('You have selected the {name()} attribute (attribute
number {position()}, at node [{generate-id()}]), of the {$PARENTNAME}
element ({$ANCESTORS}).')"><u><xsl:value-of


		<!-- Element contains children, text or processing
instructions or comments -->

			<xsl:apply-templates />

			<!-- Created the closing tag, indenting it -->

			<!-- Create whitespace for every ancestor of
node (indentation)	-->
			<xsl:for-each select="ancestor::*">&nbsp; &nbsp;
&nbsp; </xsl:for-each>
			&lt;/<FONT COLOR="880000"><xsl:value-of

		<!-- An empty element  -->


  <!-- Comments  -->
  <xsl:template match="comment()">
	<FONT COLOR="888888" SIZE="3"><PRE>&lt;!--<xsl:value-of

  <!-- Text  -->
  <xsl:template match="text()">
	<!-- Create whitespace for every ancestor of node (indentation)
	<xsl:for-each select="ancestor::*">&nbsp; &nbsp; &nbsp;
	<xsl:variable name="ANCESTORS"><xsl:for-each
select="ancestor::*">/<xsl:value-of select="name()"/>[<xsl:value-of
select="generate-id()"/>] </xsl:for-each></xsl:variable>
	<xsl:variable name="PARENTNAME"><xsl:value-of

	<FONT COLOR="0000FF"><B><A NAME="" onclick="moreInfo('You have
selected the text (node [{generate-id()}]) in the {$PARENTNAME} element


  <!-- Match the processing instructions - how do you match <?XML?> ?
  <xsl:template match="processing-instruction()">
	<!-- Create whitespace for every ancestor of node (indentation)
	<xsl:for-each select="ancestor::*">&nbsp; &nbsp; &nbsp;
	&lt;?<xsl:value-of select="name()"/> 
	<FONT>&nbsp; </FONT>
	<xsl:value-of select="."/>?&gt;


 XSL-List info and archive:

Current Thread