tree.xml:
<table>
<person>
<id>1</id>
<name>人物</name>
<parent>0</parent>
</person>
<person>
<id>2</id>
<name>武将</name>
<parent>1</parent>
</person>
<person>
<id>3</id>
<name>文臣</name>
<parent>1</parent>
</person>
<person>
<id>4</id>
<name>魏延</name>
<parent>2</parent>
</person>
<person>
<id>5</id>
<name>赵云</name>
<parent>2</parent>
</person>
<person>
<id>6</id>
<name>何平</name>
<parent>2</parent>
</person>
<person>
<id>7</id>
<name>荀域</name>
<parent>3</parent>
</person>
<person>
<id>8</id>
<name>荀攸</name>
<parent>3</parent>
</person>
<person>
<id>9</id>
<name>鲁肃</name>
<parent>3</parent>
</person>
<person>
<id>10</id>
<name>赵统</name>
<parent>5</parent>
</person>
<person>
<id>11</id>
<name>赵广</name>
<parent>5</parent>
</person>
</table>
-----------------------------------------------------------------------------------
style.xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<xsl:apply-templates select="//person[parent=0]"/>
</html>
</xsl:template>
<xsl:template match="//person">
<xsl:param name="id" select="id"/>
<div id="{$id}" onclick="s{$id}.style.display=='none'?s{$id}.style.display='block':s{$id}.style.display='none'">
<xsl:choose>
<xsl:when test="count(//person[parent=$id]) > 0">
<span style="cursor:hand">+</span>
</xsl:when>
<xsl:otherwise>-</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="name"/>
</div>
<div id="s{$id}" style="display:none;margin-left:30px;">
<xsl:apply-templates select="//person[parent=$id]"/>
</div>
</xsl:template>
</xsl:transform>
<table>
<person>
<id>1</id>
<name>人物</name>
<parent>0</parent>
</person>
<person>
<id>2</id>
<name>武将</name>
<parent>1</parent>
</person>
<person>
<id>3</id>
<name>文臣</name>
<parent>1</parent>
</person>
<person>
<id>4</id>
<name>魏延</name>
<parent>2</parent>
</person>
<person>
<id>5</id>
<name>赵云</name>
<parent>2</parent>
</person>
<person>
<id>6</id>
<name>何平</name>
<parent>2</parent>
</person>
<person>
<id>7</id>
<name>荀域</name>
<parent>3</parent>
</person>
<person>
<id>8</id>
<name>荀攸</name>
<parent>3</parent>
</person>
<person>
<id>9</id>
<name>鲁肃</name>
<parent>3</parent>
</person>
<person>
<id>10</id>
<name>赵统</name>
<parent>5</parent>
</person>
<person>
<id>11</id>
<name>赵广</name>
<parent>5</parent>
</person>
</table>
-----------------------------------------------------------------------------------
style.xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<xsl:apply-templates select="//person[parent=0]"/>
</html>
</xsl:template>
<xsl:template match="//person">
<xsl:param name="id" select="id"/>
<div id="{$id}" onclick="s{$id}.style.display=='none'?s{$id}.style.display='block':s{$id}.style.display='none'">
<xsl:choose>
<xsl:when test="count(//person[parent=$id]) > 0">
<span style="cursor:hand">+</span>
</xsl:when>
<xsl:otherwise>-</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="name"/>
</div>
<div id="s{$id}" style="display:none;margin-left:30px;">
<xsl:apply-templates select="//person[parent=$id]"/>
</div>
</xsl:template>
</xsl:transform>