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

XML to HTML... dynamic table headers from element name

Subject: XML to HTML... dynamic table headers from element names
From: "Alan K. Gay" <alan@xxxxxxxxxxxx>
Date: Wed, 30 Oct 2002 14:55:46 -0500
html dynamic table
Just getting my feet wet. using XMLSpy stylesheet designer to help
guide.   I'm converting XML to HTML, which is Microsoft's recommended
way of controlling the import of XML into Excel.  I've got the
stylesheet below in productive use.  However, I want to make one key
change. I want the name of XML elements to become the text column
headings so I can deal with files that have dynamic column names.

Suggestions appreciated.     

Here is typical XML:
<NewDataSet>
	<Table>
		<Name>Linda Britt</Name>
		<RFQCount>324</RFQCount>
		<RFQResponseCount>556</RFQResponseCount>
	</Table>
</NewDataSet>

Here is the stylesheet.  See comments regarding what I'm trying to
change.
	<xsl:template match="/">
	<html>
	<head></head>
	<body>
	<xsl:for-each select="NewDataSet">
	 <xsl:for-each select="Table">
	  <xsl:if test="position()=1">
	   <xsl:text disable-output-escaping="yes">&lt;table
border="0"&gt;</xsl:text>
	  </xsl:if>
	 <xsl:if test="position()=1">
	<thead>
	 <tr>
	  <td >
	   <span>Buyer Name</span>   	COMMENT: I want this to be
"Name" from element name.
	 </td>
	  <td >
	   <span># RFQs</span>		COMMENT: I want this to be
"RFQCount" from element name.
	  </td>
	  <td >
	   <span># Responses</span>
	  </td>
	 </tr>
	 </thead>
	</xsl:if>
	  <xsl:if test="position()=1">
	    <xsl:text
disable-output-escaping="yes">&lt;tbody&gt;</xsl:text>
	  </xsl:if>
	<tr>
	  <td>
	    <xsl:for-each select="Name">
		<xsl:apply-templates/>
		</xsl:for-each>
	  </td>
	  <td>
	    <xsl:for-each select="RFQCount">
		<xsl:apply-templates/>
	    </xsl:for-each>
	   </td>
	   <td>
	     <xsl:for-each select="RFQResponseCount">
		 <xsl:apply-templates/>
	     </xsl:for-each>
	    </td>
	   </tr>
	<xsl:if test="position()=last()">
	   <xsl:text
disable-output-escaping="yes">&lt;/tbody&gt;</xsl:text>
	</xsl:if>
	<xsl:if test="position()=last()">
	   <xsl:text
disable-output-escaping="yes">&lt;/table&gt;</xsl:text>
	</xsl:if>
	</xsl:for-each>
	</xsl:for-each>
	</body>
	</html>
	</xsl:template>
</xsl:stylesheet>


Alan K. Gay 
ProBuild, Inc. 
http://www.probuild.com



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.