xsl-list
[Top] [All Lists]

Urgent : Nested List Help

2005-02-03 14:58:25
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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>