Re: RE: Displaying XML source with XSL

Subject: Re: RE: Displaying XML source with XSL
From: "Steve Muench" <SMUENCH@xxxxxxxxxxxxx>
Date: 08 Jan 99 14:03:23 -0800
>From Microsoft Reference material on "Direct XML
Browsing in IE5" I see:

|  When using an XSL style sheet, you can access the
|  XML source through the XML Document Object Model
|  (DOM). Two additional properties are exposed on
|  the document object from DHTML:
|
|  document.XMLDocument
|  document.XSLDocument
|
|  The XMLDocument property returns the root of the
|  XML source tree, and the XSLDocument property
|  returns the root of the XSL style sheet.

I created a two-frame frameset and loaded used IE5
to directly browse an XML file in one frame while
some Script in the other frame wrote the value of:

parent.leftframe.document.XSLDocument.xml

to a text file.

I slightly modified the CSS styles to make the
font 18pt instead of 10pt (the default) for some
demos I was doing in a large room, but other than
that the default style sheet looks like what's
below.  A little cryptic, but a definitely
learning tool.

Have fun.

<?xml version="1.0" ?>
<x:template xmlns:x="uri:xsl"><HTML><HEAD>
			<STYLE>BODY{font:18pt Verdana}
.c{cursor:hand}
.b{color:red;font-family:FixedSys}
.e{margin-left:1em;text-indent:-1em;margin-bottom:3px}
.k{margin-left:1em;text-indent:-1em;margin-bottom:3px}
.t{color:#444444}
.a{color:#444444}
.tx{font-weight:bold;color:blue}
.db{text-indent:0px;margin-left:2em;margin-top:0px;margin-bottom:0px;font:18pt
Courier;color:#0044BB}
.di{font:18pt Courier;color:#0044BB}
.d{color:#0044BB}
.pi{color:#0044BB}
.cb{text-indent:0px;margin-left:2em;margin-top:0px;margin-bottom:0px;font:18pt
Courier;color:#0044BB}
.ci{font:18pt Courier;color:#0044BB}
PRE{margin:0px;display:inline}</STYLE>
			<SCRIPT>
				<x:comment>
function initState(){
var pres=document.all.tags("PRE");
for (var i=0;i&lt;pres.length;i++){
var cparent=pres(i).parentElement;
if (cparent.className=="ci"){
if (cparent.children(0).innerText.indexOf("\n")&gt;0){
cparent.className="cb";
cparent.style.display="block";
cparent.parentElement.children(0).className="c";
cparent.parentElement.children(0).children(0).innerText="-";
}}
if (cparent.className=="di"){
if (cparent.children(0).innerText.indexOf("\n")&gt;0){
cparent.className="db";
cparent.style.display="block";
cparent.parentElement.children(0).className="c";
cparent.parentElement.children(0).children(0).innerText="-";
}}}}
function changeState(e){
mark=e.children(0).children(0);
if (mark.innerText=="+"){
for (var i=1;i&lt;e.children.length;i++)
e.children(i).style.display="block";
mark.innerText="-";}
else if (mark.innerText=="-"){
for (var i=1;i&lt;e.children.length;i++)
e.children(i).style.display="none";
mark.innerText="+";
}}
function changeChunkState(e){
mark=e.children(0).children(0);
contents=e.children(1);
if (mark.innerText=="+"){
if (contents.className=="db"||contents.className=="cb")
contents.style.display="block";
else
contents.style.display="inline";
mark.innerText="-";}
else if (mark.innerText=="-"){
contents.style.display="none";
mark.innerText="+";
}}
function document_click(){
e=window.event.srcElement;
if (e.className!="c"){e=e.parentElement;if (e.className!="c"){return;}}
e=e.parentElement;
if (e.className=="e") changeState(e);
if (e.className=="k") changeChunkState(e);
}
document.onclick=document_click;
</x:comment></SCRIPT>
			<SCRIPT FOR="window"
EVENT="onload">initState();</SCRIPT>
		</HEAD>
		<BODY class="st"><x:use-templates for="."/></BODY>
	</HTML>
	<x:define-template-set>
		<x:template><x:use-templates/></x:template>
		<x:template match="node()[nodeType()=10]">
			<DIV class="e"><SPAN>
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN class="d">&lt;!DOCTYPE
<x:nodeName/><SPAN STYLE="font-style:italic"> (View Source for full
doctype...)</SPAN>&gt;</SPAN>
				</SPAN></DIV>
		</x:template>
		<x:template match="pi()">
			<DIV class="e"><DIV>
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN class="pi">&lt;?<x:nodeName/>
						<x:value-of/>?&gt;</SPAN>
				</DIV></DIV>
		</x:template>
		<x:template match="pi('xml')">
			<DIV class="e"><DIV>
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN class="pi">&lt;?<x:nodeName/>
						<x:for-each
select="@*"><x:nodeName/>="<x:value-of/>" </x:for-each>?&gt;</SPAN>
				</DIV></DIV>
		</x:template>
		<x:template match="@*"><SPAN class="a">
				<x:nodeName/>="</SPAN><x:value-of/><SPAN
class="a">"</SPAN></x:template>
		<x:template match="textnode()">
			<DIV class="e"><DIV>
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN class="tx"><x:value-of/></SPAN>
				</DIV></DIV>
		</x:template>
		<x:template match="comment()">
			<DIV class="k"><SPAN>
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN
class="t">&lt;!--</SPAN></SPAN><SPAN class="ci"><PRE><x:value-of/></PRE></SPAN>
				<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
				<SPAN class="t">--&gt;</SPAN>
			</DIV>
		</x:template>
		<x:template match="cdata()">
			<DIV class="k"><SPAN>
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN
class="t">&lt;![CDATA[</SPAN></SPAN><SPAN
class="di"><PRE><x:value-of/></PRE></SPAN>
				<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
				<SPAN class="t">]]&gt;</SPAN>
			</DIV>
		</x:template>
		<x:template match="*">
			<DIV class="e">
				<DIV><SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN
class="t">&lt;<x:nodeName/></SPAN>
					<x:apply-templates select="@*"/>
					<SPAN class="t">/&gt;</SPAN>
				</DIV></DIV>
		</x:template>
		<x:template match="*[node()]">
			<DIV class="e"><DIV class="c">
					<SPAN class="b">-</SPAN>
					<SPAN
class="t">&lt;<x:nodeName/></SPAN><x:apply-templates select="@*"/>
					<SPAN class="t">&gt;</SPAN>
				</DIV>
				<x:use-templates/>
				<SPAN class="t">
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					&lt;/<x:nodeName/>&gt;</SPAN>
			</DIV>
		</x:template>
		<x:template match="*[textnode()]">
			<DIV class="e">
				<DIV STYLE="margin-left:1em;text-indent:-2em">
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN
class="t">&lt;<x:nodeName/></SPAN><x:apply-templates select="@*"/>
					<SPAN class="t">&gt;</SPAN><SPAN
class="tx"><x:value-of/></SPAN><SPAN class="t">&lt;/<x:nodeName/>&gt;</SPAN>
				</DIV></DIV>
		</x:template>
		<x:template match="*[*]">
			<DIV class="e">
				<DIV class="c"><SPAN class="b">-</SPAN>
					<SPAN
class="t">&lt;<x:nodeName/></SPAN><x:apply-templates select="@*"/>
					<SPAN class="t">&gt;</SPAN></DIV>
				<x:use-templates/>
				<SPAN class="t"><SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					&lt;/<x:nodeName/>&gt;</SPAN>
			</DIV>
		</x:template>
		<x:template match="*[*$and$textnode()$and$$not$*/*]">
			<DIV class="e"><DIV
STYLE="margin-left:1em;text-indent:-2em">
					<SPAN class="b"><x:entityref
name="nbsp"/></SPAN>
					<SPAN
class="t">&lt;<x:nodeName/></SPAN><x:apply-templates select="@*"/><SPAN
class="t">&gt;</SPAN><x:use-templates>
						<x:template
match="textnode()"><SPAN class="tx"><x:value-of/></SPAN></x:template>
						<x:template match="*">
							<SPAN
class="t">&lt;<x:nodeName/></SPAN><x:apply-templates select="@*"/>
							<SPAN
class="t">&gt;</SPAN><x:use-templates/><SPAN
class="t">&lt;/<x:nodeName/>&gt;</SPAN></x:template>
					</x:use-templates><SPAN
class="t">&lt;/<x:nodeName/>&gt;</SPAN>
				</DIV></DIV>
		</x:template>
	</x:define-template-set>
</x:template>
_______________________________________________
Steve Muench, Consulting PM & XML Evangelist
Java Business Objects Dev't Team
smuench@xxxxxxxxxx -- http://www.oracle.com/xml
--- Begin Message ---
Subject: RE: Displaying XML source with XSL
From: "alan dennis" <alan_l_dennis@xxxxxxxxxxx>
Date: 08 Jan 99 13:10:45


----Original Message Follows----
From: "Markor, John (Non-HP)" <jmarkor@xxxxxxxxxx>
To: "'xsl-list@xxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxx>
Subject: RE: Displaying XML source with XSL
Date: Fri, 8 Jan 1999 07:17:01 -0800
Reply-To: xsl-list@xxxxxxxxxxxxxxxx

Actually, IE5b2 does something similar to this, with direct viewing of
the
XML file.  The program even allows for expansion and collapse of the XML
file, based on the mark-up.

-----Original Message-----
From: Zvi Schreiber [mailto:zvi@xxxxxxxxxxx]
Sent: Thursday, January 07, 1999 9:31 PM
To: XSL mailing list
Subject: Displaying XML source with XSL


Does anyone please have an XSL script which simply reproduces the
original
XML for displaying in a browser, i.e. produces HTML which displays the
original XML preferably indented?

Thanks

Zvi Schreiber


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
<?xml version="1.0"?>

<!-- Generic stylesheet for viewing XML -->
<xsl:template xmlns:xsl="http://www.w3.org/TR/WD-xsl";>

  <DIV STYLE="font-family:Courier; font-size:10pt; margin-bottom:2em">
    <xsl:apply-templates select="."/>
  </DIV>
  
  <xsl:templates>
    <xsl:template><xsl:apply-templates/></xsl:template>

    <xsl:template match="*">
      <DIV STYLE="margin-left:1em; color:gray">
        &lt;<xsl:nodeName/><xsl:apply-templates for="@*"/>/&gt;
      </DIV>
    </xsl:template>

    <xsl:template match="*[node()]">
      <DIV STYLE="margin-left:1em">
        <SPAN STYLE="color:gray">&lt;<xsl:nodeName/><xsl:apply-templates select="@*"/>&gt;</SPAN><xsl:apply-templates select="node()"/><SPAN STYLE="color:gray">&lt;/<xsl:nodeName/>&gt;</SPAN>
      </DIV>
    </xsl:template>

    <xsl:template match="@*">
      <SPAN STYLE="color:navy"> <xsl:nodeName/>="<SPAN STYLE="color:black"><xsl:get-value /></SPAN>"</SPAN>
    </xsl:template>

    <xsl:template match="pi()">
      <DIV STYLE="margin-left:1em; color:maroon">&lt;?<xsl:nodeName/><xsl:apply-templates select="@*"/>?&gt;</DIV>
    </xsl:template>

    <xsl:template match="cdata()"><pre>&lt;![CDATA[<xsl:get-value />]]&gt;</pre></xsl:template>

    <xsl:template match="textnode()"><xsl:get-value /></xsl:template>
  </xsl:templates>
</xsl:template>

--- End Message ---
Current Thread