Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 从祖先(不一定是兄弟)获取后代节点的位置_Xml_Xslt_Xpath - Fatal编程技术网

Xml 从祖先(不一定是兄弟)获取后代节点的位置

Xml 从祖先(不一定是兄弟)获取后代节点的位置,xml,xslt,xpath,Xml,Xslt,Xpath,在下面的xml片段中,我有一个带脚注的部分,还有一个带脚注的小节。尽管fn不是兄弟姐妹,但我想从论文/章节级别开始按顺序重新编号脚注 <?xml version='1.0' ?> <paper> <section> <title>My Main Section</title> <para>My para with a <footnote num="1">text</f

在下面的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>

我的主要部分
我的段落加了一个文本脚注。
我的分部
更多文本与另一个更多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="2">more fn text.</footnote>     footnote.</para>
    </section>
</section>
</paper>

我的主要部分
我的段落加了一个文本脚注。
我的分部
更多文本与另一个更多fn文本。脚注。
我尝试了使用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>


“将脚注重新编号,从论文/章节开始,这样fn就不是兄弟姐妹”我不确定这意味着什么。为什么不发布转换的预期结果呢?添加了预期输出,并为清晰起见进行了编辑(我希望:))完美,谢谢。我对自己没有从我搜索的文件中找到这个感到恼火