[xsl] Urgent : Nested List Help

Subject: [xsl] Urgent : Nested List Help
From: "Sefa Sevtekin" <sevtekin@xxxxxxxxxxx>
Date: Thu, 03 Feb 2005 21:58:25 +0000
Hi, I am trying to transform an XML file by using XSL and display it as html. Here is the XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="links.xsl"?>
<links>
   <link name="1">
		<link name="1.1" url="#"/>
		<link name="1.2">
			<link name="1.2.1"/>
			<link name="1.2.2"/>
		</link>
   </link>
   <link name="2">
		<link name="2.1">
			<link name="2.1.1"/>
			<link name="2.1.2"/>
			<link name="2.1.3"/>
		</link>
		<link name="2.2">
			<link name="2.2.1"/>
			<link name="2.2.2"/>
			<link name="2.2.3"/>
		</link>
		<link name="2.3"/>
   </link>
   <link name="3"/>
</links>

and here is the XSL:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
<html>
<head>
</head>
<body>


	<ul>
		<xsl:apply-templates select="links/link"/>
	</ul>


</body> </html> </xsl:template>

<xsl:template match="link">
			<li>
				<xsl:value-of select="@name"/>
			</li>
			<xsl:apply-templates />
</xsl:template>

<xsl:template match="link/link">

		<li>
					<xsl:value-of select="@name"/>
		</li>

	<ul>
		<xsl:apply-templates />
	</ul>
</xsl:template>
</xsl:stylesheet>

and here is the output html:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <html> <head> </head> <body> <ul> <li>1</li> <li>1.1</li> <ul> </ul> <li>1.2</li> <ul> <li>1.2.1</li> <ul> </ul> <li>1.2.2</li> <ul> </ul> </ul> <li>2</li> <li>2.1</li> <ul> <li>2.1.1</li> <ul> </ul> <li>2.1.2</li> <ul> </ul> <li>2.1.3</li> <ul> </ul> </ul> <li>2.2</li> <ul> <li>2.2.1</li> <ul> </ul> <li>2.2.2</li> <ul> </ul> <li>2.2.3</li> <ul> </ul> </ul> <li>2.3</li> <ul> </ul> <li>3</li> </ul> </body> </html>


The problem is xsl creates empty <ul></ul> in between. Can you help me fix it?


Thanks

Current Thread