输入XML:
<doc>
<section>
<para>Paragraph 1</para>
<para>Paragraph 2</para>
<para>Paragraph 3</para>
</section>
<para>Paragraph 4</para>
<para>Paragraph 5</para>
<para>Paragraph 6</para>
</doc>
需要的输出:
<book>
<section>
<p class="para" id="0001">Paragraph 1</p>
<p class="para" id="0002">Paragraph 2</p>
<p class="para" id="0003">Paragraph 3</p>
</section>
<p class="para" id="0004">Paragraph 4</p>
<p class="para" id="0005">Paragraph 5</p>
<p class="para" id="0006">Paragraph 6</p>
</book>
我尝试使用以下XSL,但我没有得到想要的输出。有人可以帮忙吗?
<xsl:template match="para">
<xsl:variable name="count" select="position()"/>
<p class="para" id="{$count}">
<xsl:apply-templates/>
</p>
</xsl:template>
我得到的结果是:
<p class="para" id="2">Paragraph 1</p>
<p class="para" id="4">Paragraph 2</p>
<p class="para" id="6">Paragraph 3</p>
<p class="para" id="4">Paragraph 4</p>
<p class="para" id="6">Paragraph 5</p>
<p class="para" id="8">Paragraph 6</p>
- VSe段落1
段落2
段落3
段落4
段落5
段落6