[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

onLoad Collapsing of subtree.

Subject: onLoad Collapsing of subtree.
From: "Brahadambal Srinivasan" <brahadambal@xxxxxxxxx>
Date: Tue, 2 May 2006 11:07:18 +0530
td onload
I have the folowwing sample XML and XSLT.

I want all the nodes to be collapsed on load! Is it possible? Please
help me out.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="XMLexample.xsl" type="text/xsl" ?>
<TS>
	<Table1>
		<fld1>0</fld1>
		<disc1>
			<dfld1>7</dfld1>
			<loop3>
				<lfld2>170</lfld2>
				<loop4>
					<lfld3>40</lfld3>
				</loop4>
			</loop3>
			<fld3>1025</fld3>
		</disc1>
		<loop1>
			<lfld1>1030</lfld1>
		</loop1>
		<loop1>
			<lfld1>1031</lfld1>
			<loop2>
				<disc1>
					<dfld1>7</dfld1>
					<loop3>
						<lfld2>170</lfld2>
						<loop4>
							<lfld3>40</lfld3>
						</loop4>
					</loop3>
					<fld3>1025</fld3>
				</disc1>
				<disc2>
					<fld2>1200908</fld2>
					<Iterate1>
						<lfld4>700</lfld4>
						<Iterate2>
							<fld5>7</fld5>
							<Iterate3>
								<fld6>7</fld6>
								<fld7>7</fld7>
							</Iterate3>
							<fld8>7</fld8>
						</Iterate2>
					</Iterate1>
					<fld3>1025</fld3>
				</disc2>
			</loop2>
			<fld10>1024</fld10>
		</loop1>
	</Table1>
</TS>

XSLT is:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
	<xsl:template match="/TS">
		<html>
			<head>
				<title>XML in Tree View</title>
				<meta name="generator" content="ZZEE Art HTML Listing"/>
				<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
				<style type="text/css">
					<!--
						body
						{
							font-family: "Times New Roman";
							font-size: 12pt;
							background-color: #ffffff;
							color: #000000;
							text-align: left;
						}
						ul.zzul {list-style-type:none; display: block;}
						span.zzspace {left:11px;}
						a, a:visited {color: #0000ff;}
						a:hover { color: #ff0000;}
					-->
				</style>
				<!-- [client side code for collapsing and unfolding branches] -->
				<script language="JavaScript">
					function Toggle(node)
					{
						// Unfold the branch if it isn't visible
						if (node.nextSibling.style.display == 'none')
						{
							// Change the image (if there is an image)
							if (node.children.length > 0)
							{
								if (node.children.item(0).tagName == "IMG")
								{
									node.children.item(0).src = "minus.gif";
								}
							}

							node.nextSibling.style.display = '';
						}
						// Collapse the branch if it IS visible
						else
						{
							// Change the image (if there is an image)
							if (node.children.length > 0)
							{
								if (node.children.item(0).tagName == "IMG")
								{
									node.children.item(0).src = "plus.gif";
								}
							}

							node.nextSibling.style.display = 'none';
						}

					}
				</script>
			</head>
			<body>
				<ul style="list-style-type:none; margin:0; padding:0;">
					<table border="0">
						<tr>
							<td>
								<xsl:apply-templates select="." mode="render"/>
							</td>
						</tr>
					</table>
				</ul>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="/" mode="render">
		<xsl:apply-templates mode="render"/>
	</xsl:template>
	<xsl:template match="*" mode="render">
		<table border="0">
			<tr>
				<td/>
				<td/>
				<td/>
				<td>
					<a onClick="Toggle(this)">
						<img src="minus.gif"/>
						<xsl:text>  </xsl:text>
						<xsl:value-of select="local-name()"/>
					</a>
					<div>
						<xsl:apply-templates select="@*" mode="render"/>
						<xsl:apply-templates mode="render"/>
					</div>
				</td>
			</tr>
		</table>
	</xsl:template>
	<xsl:template match="text()" mode="render">
		<xsl:call-template name="escape-ws">
			<xsl:with-param name="text" select="translate(.,' ',' ')"/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="escape-ws">
		<xsl:param name="text"/>
		<xsl:choose>
			<xsl:when test="contains($text, ' ')">
				<xsl:call-template name="escape-ws">
					<xsl:with-param name="text" select="substring-before($text, ' ')"/>
				</xsl:call-template>
				<xsl:call-template name="escape-ws">
					<xsl:with-param name="text" select="substring-after($text, ' ')"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="contains($text, ' ')">
				<xsl:value-of select="substring-before($text, ' ')"/>
				<xsl:call-template name="escape-ws">
					<xsl:with-param name="text" select="substring-after($text, ' ')"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$text"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

TIA.
Brady.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.