2017-01-08 7 views
0

私のXML文書では、メモの呼び出しと文末がありますが、明らかに文書の同じ場所にはありません。正確に同じ数の<notecalls>要素と<endnote>要素があることが確かめられます。 XSLを使用して、対応する<endnote>のコンテンツ(つまり、最初の<notecall>要素が最初の<endnote>要素と一緒に移動するなど)を検索して、番号とエンドノートの内容で構成される新しい要素を作成します。xsl:numberでn番目の要素を取得する

私は以下のようにxsl:number関数を使用しました。ただし、出力ファイルでは再番号付けは正しいものの、取り出されるノートの内容は常に最初の最後の要素です。私はここで何が欠けていますか? XSLファイルから

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

と関連する部分:ここで

は私のXML構造がどのように見えるかです

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

答えて

2

あなたがXSLT 2.0以降を使用する

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

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

を変更する場合は、あなたの変数が結果ツリーフラグメントではなく番号であるとそうでない<xsl:value-of select="(//endnote)[position() = $posit]"/><xsl:value-of select="(//endnote)[$posit]"/>を変更する、ようにそれを使用します明示的に比較する必要のある位置、または<xsl:value-of select="(//endnote)[number($posit)]"/>の数値に変換します。

+0

シンプル:ありがとうございます。それはそれを解決する、私は何かを理解した。 – DonRamiro

関連する問題