私は知っていると言うことから始めましょうposition()
が、このコンテキストでそれを機能させる方法を理解できないようです.
私がやろうとしているのは、テキストの本文を繰り返し処理して、すべての画像を見つけることです。これらは、「図 1」などのリンクに変わります。番号はposition()
、異なるノード セット内の対応するノードの によって提供されます。
これが私の XML のサンプルです。
<understanding-individual-question>
<section id="18" handle="questions">Questions</section>
<entry id="162">
<images items="3">
<item id="215">
<description mode="normal" handle="winter-frozen-period-for-stile-s-pond" word-count="6">Winter frozen period for Stile’s Pond.</description>
<file size="73 KB" path="/uploads" type="image/jpg">
<filename>lakefrozen-1276880623.jpg</filename>
<meta creation="2010-06-18T13:03:43-04:00" width="532" height="479" />
</file>
<title mode="normal" handle="stiles-pond-frozen" word-count="3">Stile's Pond Frozen</title>
</item>
</images>
</entry>
</understanding-individual-question>
XML の別の場所からそのノードの位置を取得するためにさまざまな方法を試しましたが、item
エラーを返し続けNaN
ます。
私が試した XSLT の 3 つの例を次に示します。
<xsl:template match="information//img">
<xsl:variable name="link" select="substring-after(@src,'uploads/')" />
<em>(<a rel="figure" href="{@src}">
<xsl:text>See Figure </xsl:text>
<!-- Method 1: Returns all as 'NaN' -->
<xsl:number value="/data/understanding-individual-question/entry/images/item[file/filename = $link][position()]" format="1"/>
<!-- Method 2: Returns all as '1' -->
<xsl:for-each select="/data/understanding-individual-question/entry/images/item[file/filename = $link]">
<xsl:number value="position()" format="1"/>
</xsl:for-each>
<!-- Method 3: Returns all as '2' -->
<xsl:number value="position()" format="1"/>
</a>.)</em>
</xsl:template>
確認XPATH
したところ、正しいノードが返されました。問題ありません。ただし、何をしてもposition()
、ノードの が返されることはありません! そして、私はその理由を理解できません。
この質問の解決策に従ってみましたが、取得し続けましNaN
た。
誰でもこれを行う方法を知っていますか?