我有下面的 xml 文档。
<toc-div>
<toc-item>
<toc-title>CHAPTER 1 INTRODUCTION</toc-title>
<toc-subitem num="1.">
<toc-title>The British Virgin Islands</toc-title>
<toc-pg>1.001</toc-pg>
</toc-subitem>
<toc-subitem num="2.">
<toc-title>History and early constitutional developments</toc-title>
<toc-pg>1.003</toc-pg>
</toc-subitem>
<toc-subitem num="3.">
<toc-title>Development as a financial centre</toc-title>
<toc-pg>1.008</toc-pg>
</toc-subitem>
<toc-subitem num="4.">
<toc-title>Common Law and Equity</toc-title>
<toc-pg>1.015</toc-pg>
</toc-subitem>
<toc-subitem num="5.">
<toc-title>Statutes</toc-title>
<toc-pg>1.017</toc-pg>
</toc-subitem>
<toc-subitem num="6.">
<toc-title>Taxation</toc-title>
<toc-pg>1.022</toc-pg>
</toc-subitem>
</toc-item>
我正在应用下面的xslt。
<xsl:template match="toc-subitem">
<table>
<td>
<xsl:value-of select="preceding-sibling::toc-title[1]"/>
</td></table>
<xsl:variable name="tocpg">
<xsl:value-of select="current()/toc-pg"/></xsl:variable>
<xsl:variable name="abc">
<xsl:choose>
<xsl:when test="not(contains(@num, '('))">
<xsl:value-of select="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="before">
<xsl:value-of select="normalize-space(substring-before($tocpg, '.'))"/>
</xsl:variable>
<xsl:variable name="after">
<xsl:value-of select="normalize-space(substring-after($tocpg, '.'))"/>
</xsl:variable>
<xsl:variable name="z">
<xsl:value-of select="current()/@num"/>
</xsl:variable>
<xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
<xsl:variable name="numa" select="number(translate(@num, '.', ''))" />
<xsl:variable name="itemlevel">
<xsl:value-of select="$ThisDocument//ntw:nums[@num=$abc]/@word"/>
</xsl:variable>
<xsl:variable name="tocitemlevel">
<xsl:value-of select="concat('toc-item-', $itemlevel,'-level')"/>
</xsl:variable>
<xsl:variable name="conc">
<xsl:value-of select="concat('er:#BVI_CH_0',$before, '/P', normalize-space($tocpgtag))"/>
</xsl:variable>
<table class="{$tocitemlevel}">
<tbody>
<tr>
<td class="toc-subitem-num">
<xsl:value-of select="$z" />
</td>
<td class="toc-title">
<xsl:value-of select="current()/toc-title" />
</td>
<td class="toc-pg">
<a href="{$conc}">
<xsl:value-of select="current()/toc-pg" />
</a>
</td>
</tr>
</tbody>
</table>
</xsl:template>
当我应用这个模板时,我得到的输出如下。
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">1.</td>
<td class="toc-title">The British Virgin Islands</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-001">1.001</a></td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">2.</td>
<td class="toc-title">History and early constitutional developments</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-003">1.003</a></td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">3.</td>
<td class="toc-title">Development as a financial centre</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-008">1.008</a></td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">4.</td>
<td class="toc-title">Common Law and Equity</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-015">1.015</a></td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">5.</td>
<td class="toc-title">Statutes</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-017">1.017</a></td>
</tr>
</tbody>
</table>
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">6.</td>
<td class="toc-title">Taxation</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-022">1.022</a></td>
</tr>
</tbody>
</table>
但我想得到它如下
<table>
<td>CHAPTER 1 INTRODUCTION</td>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">1.</td>
<td class="toc-title">The British Virgin Islands</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-001">1.001</a></td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">2.</td>
<td class="toc-title">History and early constitutional developments</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-003">1.003</a></td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">3.</td>
<td class="toc-title">Development as a financial centre</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-008">1.008</a></td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">4.</td>
<td class="toc-title">Common Law and Equity</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-015">1.015</a></td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">5.</td>
<td class="toc-title">Statutes</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-017">1.017</a></td>
</tr>
</tbody>
</table>
<table class="toc-item--level">
<tbody>
<tr>
<td class="toc-subitem-num">6.</td>
<td class="toc-title">Taxation</td>
<td class="toc-pg"><a href="er:#BVI_CH_01/P1-022">1.022</a></td>
</tr>
</tbody>
</table>
请让我知道我哪里出错了。
谢谢