在我的XML文档中,我有note调用和endnote,显然不在文档中相同的位置。我可以肯定,<notecalls>元素和<endnote>元素的数量完全相同。对于XSL,我想检索相应的<endnote>的内容(即:第一个<notecall>元素与第一个<endnote>元素一起使用)来创建一个由数字和尾注的内容组成的新元素。
为此,我使用了xsl:number函数,如下所示;但是检索到的注释的内容始终是第一个尾注元素,尽管在输出文件中重编号是正确的。我在这里错过了什么?
下面是我的XML结构看起来是什么样子的:
<main_text>Some text<notecall>1</notecall> some other text </main_text>
<main_text>More and more long text<notecall>2</notecall> and more even</main_text>
<main_text>And some more again <notecall>3</notecall> etc…<main_text>
<endnote>The content of the first endnote</endnote>
<endnote>The content of the second one</endnote>
<endnote>The content of the third one</endnote>以及XSL文件的相关部分:
<xsl:template match="notecall">
<xsl:variable name="posit">
<xsl:number level="any"/>
</xsl:variable>
<seg>
<xsl:value-of select="$posit"/>
<note><xsl:value-of select="(//endnote)[$posit]"/></note>
</seg>
</xsl:template>我想要:
<p>Some text<seg>1<note>The content of the first endnote</note></seg> some other text</main_text>
<p>More and more long text<seg>2<note>The content of the second one</note></seg> and more even</main_text>
<p>And some more again <seg>3<note>The content of the third one</note></seg> etc…</main_text>但我得到的是:
<p>Some text<seg>1<note>The content of the first endnote</note></seg> some other text</main_text>
<p>More and more long text<seg>2<note>The content of the first endnote</note></seg> and more even</main_text>
<p>And some more again <seg>3<note>The content of the first endnote</note></seg> etc…</main_text>发布于 2017-01-08 17:50:14
如果使用XSLT2.0或更高版本,则更改
<xsl:variable name="posit">
<xsl:number level="any"/>
</xsl:variable>至
<xsl:variable name="posit" as="xs:integer">
<xsl:number level="any"/>
</xsl:variable>否则,将<xsl:value-of select="(//endnote)[$posit]"/>更改为<xsl:value-of select="(//endnote)[position() = $posit]"/>,因为您的变量是结果树片段,而不是数字,因此要使用它作为需要显式比较的位置,或者将其转换为与<xsl:value-of select="(//endnote)[number($posit)]"/>对应的数字。
https://stackoverflow.com/questions/41535567
复制相似问题