RE: [xsl] Dsiplayig xml in tables

Subject: RE: [xsl] Dsiplayig xml in tables
From: "Ricaud Matthieu" <matthieu.ricaud@xxxxxxx>
Date: Wed, 10 Mar 2004 12:26:14 +0100
Hi !

I had written a stylesheet that display any xml file in table (clicking on a case display the childrens), maybe it can help you.
(It works fine on IE, i did not test other browsers...)

So this is it : 

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="html" encoding="Windows-1252"/>

	<xsl:template match="/*">
		<html>
		
		<style type="text/css">
		.FERME {background-color:#BBBBCC; font-family: Verdana; font-size: 8pt; cursor:pointer;}
		.OUVERT { background-color:#EEF3FB; font-style:blod;font-family: Verdana; font-size: 8pt; cursor:pointer;}
		.DERNIER { font-style:blod;font-family: Verdana; font-size: 8pt;}
		.VALEURNOEUD { background-color:#FFFFCC; font-family: Verdana; font-size: 8pt;}
		.ATTRIBUT {color:#999999;}
		</style>
		
		
		<script language="javascript">
			function affiche_cache(objet){
			ObjetCible=objet.parentNode.nextSibling;
			if (ObjetCible.style.display=="none"){
			    ObjetCible.style.display="block";
			    objet.className="OUVERT";
			      }
			else{    
			    ObjetCible.style.display="none";
			    objet.className="FERME";
			    }
			}
		</script>

			<body>		
				<table width="100%" align="center" border="1">
					<tr>
						<td width="100%" align="center" class="OUVERT" onclick="javascript:affiche_cache(this);">
							<xsl:attribute name="colspan"><xsl:value-of select="count(child::*)"/></xsl:attribute>
							<b><xsl:value-of select="name()"/></b>
	                				(<span class="ATTRIBUT"><xsl:for-each select="@*"><b><xsl:value-of select="name()"/></b> : <i><xsl:value-of select="."/></i>&#160;&#160;</xsl:for-each></span>)    
                  				</td>
					</tr>
					<tr>
						<xsl:apply-templates select="*"/>
					</tr>
				</table>
			</body>
		</html>
	</xsl:template>
	
	
	<xsl:template match="*">
		<td valign="top" bgcolor="white">
			<xsl:choose>
				
				<xsl:when test="*">
					<table width="100%" align="center" border="1">
						<tr>
							<td width="100%" align="center" class="FERME" onclick="javascript:affiche_cache(this);">
								<xsl:attribute name="colspan"><xsl:value-of select="count(child::*)"/></xsl:attribute>
								<b>	<xsl:value-of select="name()"/></b>
								 (<span class="ATTRIBUT"><xsl:for-each select="@*"><b><xsl:value-of select="name()"/></b> : <i><xsl:value-of select="."/></i>&#160;&#160;</xsl:for-each></span>)
							 </td>		
						</tr>
						<tr style="display:none">
							<xsl:apply-templates select="*"/>
						</tr>
					</table>
				</xsl:when>
				
				<xsl:otherwise>
					<div class="DERNIER">
					<b><xsl:value-of select="name()"/></b>						
					 (<span class="ATTRIBUT"><xsl:for-each select="@*"><b><xsl:value-of select="name()"/></b> : <i><xsl:value-of select="."/></i>&#160;</xsl:for-each></span>)
					 </div>
					 <div class="VALEURNOEUD"><xsl:value-of select="."/></div>
         			</xsl:otherwise>
			
			</xsl:choose>
		</td>
	</xsl:template>
</xsl:stylesheet>


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


Current Thread