This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: populating tables (long)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]