5

次の XML ドキュメントがあります。

<text xmlns:its="http://www.w3.org/2005/11/its" >
 <its:rules version="2.0">
  <its:termRule selector="//term" term="yes" termInfoPointer="id(@def)"/>
 </its:rules>
 <p>We may define <term def="TDPV">discoursal point of view</term>
 as <gloss xml:id="TDPV">the relationship, expressed through discourse
  structure, between the implied author or some other addresser,
  and the fiction.</gloss>
 </p>
</text>

termInfoPointer<gloss xml:id="TDPV">要素を指す XPath 式です。

LINQ-to-XML を使用して選択します。

XElement term = ...;
object value = term.XPathEvaluate("id(@def)");

次の例外が発生します。System.NotSupportedException: This XPathNavigator does not support IDs.

この問題の解決策が見つからなかったのでid()、他の式に置き換えようとしました:

//*[@xml:id='TDPV'] // works, but I need to use @def

//*[@xml:id=@def]
//*[@xml:id=@def/text()]
//*[@xml:id=self::node()/@def/text()]

しかし、これらの作品のどれも。

それを実装id()または別の式に置き換える方法はありますか?

id()この式はid(@def) | id(//*[@attr="(id(@abc()))))))"]).

4

1 に答える 1

5

def属性が XML ドキュメント内で 1 回だけ出現することが保証されている場合は、次を使用します。

//*[@xml:id = //@def]

異なる属性が存在する可能性がある場合はdef、必要な属性を正確に選択する XPath 式を提供する必要がありdefます。

//*[@xml:id = someExpressionSelectingTheWantedDefAttribute]

XSLT ベースの検証:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
     <xsl:copy-of select="//*[@xml:id = //@def]"/>
 </xsl:template>
</xsl:stylesheet>

この変換が提供された XML ドキュメントに適用されると、次のようになります。

<text xmlns:its="http://www.w3.org/2005/11/its" >
 <its:rules version="2.0">
  <its:termRule selector="//term" term="yes" termInfoPointer="id(@def)"/>
 </its:rules>
 <p>We may define <term def="TDPV">discoursal point of view</term>
 as <gloss xml:id="TDPV">the relationship, expressed through discourse
  structure, between the implied author or some other addresser,
  and the fiction.</gloss>
 </p>
</text>

XPath 式が評価され、この評価の結果 (選択された要素) が出力にコピーされます

<gloss xmlns:its="http://www.w3.org/2005/11/its" xml:id="TDPV">the relationship, expressed through discourse
  structure, between the implied author or some other addresser,
  and the fiction.</gloss>
于 2013-02-24T17:08:32.687 に答える