RE: [xsl] XML to HTML... dynamic table headers from element names

Subject: RE: [xsl] XML to HTML... dynamic table headers from element names
From: Adam Griffin <agriffin@xxxxxxxxxxxx>
Date: Wed, 30 Oct 2002 15:15:13 -0500
something to the effect of... see below ... should work. (only first row of
data, read their names) this would eliminate the need for position test of
if block.

-adam

<tr>
<xsl:for-each select="Table[1]/*">
	<xsl:value-of select="local-name()"/>
</xsl:for-each>
</tr>



-----Original Message-----
From: Alan K. Gay [mailto:alan@xxxxxxxxxxxx]
Sent: Wednesday, October 30, 2002 2:56 PM
To: XSLT List
Subject: [xsl] XML to HTML... dynamic table headers from element names


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

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


Current Thread