22

要素の特定の修飾子ノードの連結値を含むが、他のノードを無視する文字列値を返すXPath式形式を提案できますか?

<div>
    This text node should be returned.
    <em>And the value of this element.</em>
    And this.
    <p>But this paragraph element should be ignored.</p>
</div>

戻り値は単一の文字列である必要があります。

This text node should be returned. And the value of this element. And this.

これは単一のXPath式で可能ですか?

ありがとう。

4

7 に答える 7

29

XPath 2.0の場合

string-join(/*/node()[not(self::p)], '')

于 2009-09-10T13:55:29.103 に答える
20

XPath 1.0 では:

使用できます

/div//text()[not(parent::p)]

必要なテキスト ノードをキャプチャします。連結自体は XPath 1.0 では実行できません。ホスト アプリケーションで実行することをお勧めします。

于 2009-09-10T09:30:08.653 に答える
6

機能するこの外観:

コンテキストとして使用/div/:

text() | em/text()

またはコンテキストを使用せずに:

/div/text() | /div/em/text()

最初の 2 つの文字列を連結する場合は、次のようにします。

concat(/div/text(), /div/em/text())
于 2009-09-10T08:13:31.703 に答える
6
/div//text()

中間ノードに関係なくテキストを抽出するための二重スラッシュの力

于 2009-09-10T08:14:48.270 に答える
-2

for-each ループも使用して、このように変数の値を組み立てることができます

<xsl:variable name="newstring">
    <xsl:for-each select="/div//text()">
      <xsl:value-of select="."/>
    </xsl:for-each>
  </xsl:variable>
于 2013-05-21T15:00:24.217 に答える