Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] onLoad Collapsing of subtree.

From: "Brahadambal Srinivasan" <brahadambal@--------->
To:
Date: 5/2/2006 5:38:00 AM
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.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent