1

私はいくつかのXMLを持っています

<p>Lorem ipsum dolor sit amet,<unclear reason="illegible"/> elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
quis nostrud exercitation ullamco laboris <unclear reason="illegible"/> ex ea 
commodo consequat. Duis aute irure dolor in reprehenderit in 
voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
<unclear reason="illegible"/> non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum</p>

走ってみると

<xsl:value-of select="/p" disable-output-escaping="yes"/> 

xml タグは返されません。タグを value-of クエリに含めるにはどうすればよいですか?

文中の不明確なタグを特定するための何かを含めて、文全体を含めたいと思います。

4

1 に答える 1

1

その通りです。anvalue-of要素は、定義上、すべての子孫テキスト ノードを連結したものです。「値のクエリにタグを含める」ことはできませんが、copy-of代わりに、子 (テキストノードと要素) を含む要素value-of全体を出力にコピーすることはできます。p

<xsl:copy-of select="/p" />

または、要素のコンテンツが必要でp、周囲のタグ<p></p>タグが必要ない場合 (たとえば、コンテンツを別の要素に挿入する場合)

<xsl:copy-of select="/p/node()" />

unclear要素をそのまま含めるのではなく別のものに変換する場合は、代わりにID テンプレートベースの変換を使用することをお勧めします。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- copy everything from input to output verbatim, except where
       a more specific template applies -->
  <xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
  </xsl:template>

  <!-- handle unclear elements differently -->
  <xsl:template match="unclear">
    <xsl:text>__UNCLEAR__</xsl:text>
  </xsl:template>
</xsl:stylesheet>

あなたのサンプル入力を考えると、これは生成します

<p>Lorem ipsum dolor sit amet,__UNCLEAR__ elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
quis nostrud exercitation ullamco laboris __UNCLEAR__ ex ea 
commodo consequat. Duis aute irure dolor in reprehenderit in 
voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
__UNCLEAR__ non proident, sunt in culpa qui 
officia deserunt mollit anim id est laborum</p>
于 2013-07-18T16:52:03.470 に答える