输入 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>