使用:
string(//div[@id='theNode'])
この式が評価されるとき、結果は文書内の最初の(できればのみ)div
要素の文字列値です。
要素の文字列値は、すべてのテキストノードの子孫のドキュメント順の連結としてXPath Specificationに定義されているため、これはまさに必要な文字列です。
これは、すべての空白のテキストノードの数を含めることができますので、あなたが連続した先頭と末尾の空白を排除し、単一の空白文字でどのような中間の空白を置き換えたいことがあります。
使用します
normalize-space(string(//div[@id='theNode']))
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="string(//div[@id='theNode'])"/>"
===========
"<xsl:copy-of select="normalize-space(string(//div[@id='theNode']))"/>"
</xsl:template>
</xsl:stylesheet>
この変換が提供されるXML文書に適用されます。
<div id='theNode'> This is an
<span style="color:red">example</span>
<b>bolded</b> text
</div>
2つのXPath式が評価され、これらの評価の結果を出力にコピーされます。
" This is an
example
bolded text
"
===========
"This is an example bolded text"
私の答えは、現在受け入れられている回答とは異なり、正しいと思うかもしれません。 –