RE: [xsl] populating tables (long)

Subject: RE: [xsl] populating tables (long)
From: Joshua.Kuswadi@xxxxxxxxxxxxxxxxxxxx
Date: Mon, 12 Nov 2001 10:38:39 +1100
Hi Klaus,

I've put this stylesheet together which transforms your given XML doc to produce the expected XML. I hope that this is generic enough for your needs. In particular, when you mention that "the number of levels is not known", I'm hoping that you meant the number of LEVEL_1, LEVEL_2 and/or LEVEL_3 items, not that there is the possibility of LEVEL_4, LEVEL_5 etc

Hope this helps,
Joshua


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" omit-xml-declaration="yes"/>
	<xsl:template match="/ROOT">
		<table border="1">
			<xsl:apply-templates select="LEVEL_1"/>
		</table>
	</xsl:template>
	
	<xsl:template match="LEVEL_1">
		<tr>
			<td rowspan="{count(LEVEL_2/LEVEL_3)}"><xsl:value-of select="@l1_attr" /></td>
			<td rowspan="{count(LEVEL_2[1]/LEVEL_3)}"><xsl:value-of select="LEVEL_2/@l2_attr" /></td>
			<td rowspan="{count(LEVEL_2[1]/LEVEL_3)}"><xsl:value-of select="LEVEL_2/UNIQUE_LVL_2" /></td>
			<td><xsl:value-of select="LEVEL_2/LEVEL_3/@l3_attr" /></td>
		</tr>
		<xsl:apply-templates select="LEVEL_2[1]/LEVEL_3[position() != 1]" />
		<xsl:apply-templates select="LEVEL_2[position() != 1]" />
	</xsl:template>
	
	<xsl:template match="LEVEL_2">
		<tr>
			<td rowspan="{count(LEVEL_3)}"><xsl:value-of select="@l2_attr" /></td>
			<td rowspan="{count(LEVEL_3)}"><xsl:value-of select="UNIQUE_LVL_2" /></td>
			<td><xsl:value-of select="LEVEL_3/@l3_attr" /></td>
		</tr>
		<xsl:apply-templates select="LEVEL_3[position() != 1]" />
	</xsl:template>
	
	<xsl:template match="LEVEL_3">
		<tr>
			<td><xsl:value-of select="@l3_attr"/></td>
		</tr>
	</xsl:template>
</xsl:stylesheet>

------------------------------------------------------------------------------
This message and any attachment is confidential and may be privileged or otherwise protected from disclosure.  If you have received it by mistake please let us know by reply and then delete it from your system; you should not copy the message or disclose its contents to anyone.





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


Current Thread