Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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 使用xsl:number检索第n个元素_Xml_Xslt - Fatal编程技术网

Xml 使用xsl:number检索第n个元素

Xml 使用xsl:number检索第n个元素,xml,xslt,Xml,Xslt,在我的XML文档中,我有note调用和endnote,显然不在文档中的同一位置。我可以确定元素和元素的数量完全相同。使用XSL,我希望检索相应的(即:第一个元素和第一个元素一起,依此类推)的内容,以创建一个由数字和尾注内容组成的新元素 我为此使用了xsl:number函数,如下所示;但检索到的注释内容始终是第一个尾注元素,尽管在输出文件中重新编号是正确的。我错过了什么 以下是我的XML结构的外观: <main_text>Some text<notecall>1</n

在我的XML文档中,我有note调用和endnote,显然不在文档中的同一位置。我可以确定
元素和
元素的数量完全相同。使用XSL,我希望检索相应的
(即:第一个
元素和第一个
元素一起,依此类推)的内容,以创建一个由数字和尾注内容组成的新元素

我为此使用了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>
一些文本1一些其他文本
越来越长的文本2越来越均匀
还有更多的3等等…
第一个尾注的内容
第二部分的内容
第三部分的内容
以及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>
一些文本1第一个尾注的内容一些其他文本
越来越长的文本2第二个文本的内容越来越均匀
还有第三部分的内容等等…
但我得到的是:

<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>
一些文本1第一个尾注的内容一些其他文本
越来越长的文本2第一个尾注的内容越来越均匀
还有一些是第一个尾注的内容等等…

如果使用XSLT 2.0或更高版本,请更改

<xsl:variable name="posit">
    <xsl:number level="any"/>
</xsl:variable>



否则,将
更改为
,因为您的变量是结果树片段而不是数字,所以要将其用作需要显式比较的位置,或者,如果使用XSLT 2.0或更高版本,可以使用
转换为数字

<xsl:variable name="posit">
    <xsl:number level="any"/>
</xsl:variable>



否则,将
更改为
,因为您的变量是结果树片段而不是数字,所以要将其用作需要显式比较的位置,或者,也可以使用

转换为数字:谢谢。这就解决了问题,我明白了。简单地说:谢谢。这就解决了问题,我明白了一些事情。