具有根的XSL可伸缩链接树

| 这是一个XSLT代码:
<xsl:stylesheet version=\"1.0\"  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
<xsl:output omit-xml-declaration=\"yes\"/>
<xsl:template match=\"*[parent::*]\">
  <xsl:param name=\"pPath\"/>
  <xsl:value-of select=\"$pPath\"/>
  <xsl:variable name=\"vValue\" select=\"normalize-space(text()[1])\"/>
  <xsl:value-of select=\"$vValue\"/>
  <br/>
  <xsl:apply-templates select=\"*\">
    <xsl:with-param name=\"pPath\" select=\"concat($pPath, $vValue, \': \')\"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match=\"text()\"/>
  应用于此XML时:
<ItemSet>
<Item>1
 <iteml1>1.1</iteml1>
 <iteml1>1.2</iteml1>
</Item>
<Item>2
  <iteml1>2.1
    <iteml2>2.1.1</iteml2>
   </iteml1>
</Item>
</ItemSet> 
结果是:
1
1: 1.1
1: 1.2
2
2: 2.1
2: 2.1: 2.1.1
我应该添加些什么,以便可以在该树的每个要素上都有一个链接,例如:
<a href=\"1\">1</a>
<a href=\"1\">1</a> : <a href=\"1/1.1\">1.1</a>
<a href=\"1\">1</a> : <a href=\"1/1.2\">1.2</a>
<a href=\"2\">2</a>
<a href=\"2\">2</a> : <a href=\"2/2.1\">2.1</a>
<a href=\"2\">2</a> : <a href=\"2/2.1\">2.1</a> : <a href=\"2/2.1/2.1.1\">2.1.1</a>
等等...     
已邀请:
        您不必为此进行递归处理:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<xsl:stylesheet version=\"1.0\"  xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">
    <xsl:output omit-xml-declaration=\"yes\"/>
    <xsl:template match=\"*[parent::*]\">
      <xsl:variable name=\"curr-id\" select=\"generate-id()\" />
      <xsl:for-each select=\"ancestor-or-self::*[parent::*]\">
        <xsl:variable name=\"curr-sub-id\" select=\"generate-id()\" />
        <a>
            <xsl:attribute name=\"href\">
              <xsl:for-each select=\"ancestor-or-self::*[parent::*]\">
                <xsl:value-of select=\"normalize-space(text()[1])\"/>
                <xsl:if test=\"generate-id() != $curr-sub-id\">
                    <xsl:text>/</xsl:text>
                </xsl:if>
              </xsl:for-each>
            </xsl:attribute>
            <xsl:value-of select=\"normalize-space(text()[1])\"/>
        </a>
        <xsl:if test=\"generate-id() != $curr-id\">
            <xsl:text>:</xsl:text>
        </xsl:if>
      </xsl:for-each>
      <br/>
      <xsl:apply-templates select=\"*\" />
    </xsl:template>
</xsl:stylesheet>
    

要回复问题请先登录注册