在下面的xml片段中,我有一个带脚注的部分,以及一个带脚注的子部分。我想从纸张/部分级别开始对脚注进行重新编号,尽管事实上fn不是同级的

<?xml version='1.0' ?>
<paper>
    <section>
        <title>My Main Section</title>
        <para>My para with a <footnote num="1">text</footnote> footnote.</para>
        <section>
            <title>my subsection</title>
            <para>more text with another <footnote num="1">more fn text.</footnote> footnote.</para>
        </section>
    </section>
</paper>


预期的输出将是:

<?xml version='1.0' ?>
<paper>
<section><title>My Main Section</title>
    <para>My para with a <footnote num="1">text</footnote> footnote.</para>
    <section><title>my subsection</title>
    <para>more text with another <footnote num="2">more fn text.</footnote>     footnote.</para>
    </section>
</section>
</paper>


我正在尝试使用xsl:number进行各种操作,但无法进行任何操作。我能得到的最接近的是:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="footnote/@num">
    <xsl:attribute name="num"><xsl:value-of select="count(ancestor::paper/section//footnote)"/></xsl:attribute>
</xsl:template>

</xsl:stylesheet>


的正确计数为2,但是我不确定如何指示“我是本主要部分的两个脚注中的第一个”。

我还尝试编写这样的命名模板:

<xsl:template match="/paper/section">
    <section>
        <xsl:call-template name="renumberFNs"/>
        <xsl:apply-templates/>
    </section>
</xsl:template>

<xsl:template name="renumberFNs">
    <xsl:for-each select=".//footnote/@num">
        <xsl:attribute name="num"><xsl:value-of select="position()"/></xsl:attribute>
    </xsl:for-each>
</xsl:template>


但这会将@num放在该节上。有任何想法吗?

最佳答案

这对您有用吗?

<xsl:template match="footnote/@num">
    <xsl:attribute name="num">
        <xsl:number count="footnote" level="any" from="paper/section"/>
    </xsl:attribute>
</xsl:template>

10-07 13:10