XSLT <xsl:preserve-space> と<xsl:strip-space>要素
完全な XSLT 要素リファレンス
定義と使い方
<xsl:preserve-space> 要素は、空白を保持する要素を定義するために使用されます。
<xsl:strip-space> 要素は、空白を削除する要素を定義するために使用されます。
注:空白の保持はデフォルト設定なので、<xsl:preserve-space> 要素は <xsl:strip-space> 要素を使用する場合にのみ必要です。
注:<xsl:preserve-space> 要素と <xsl:strip-space> 要素はどちらもトップレベル要素です。
構文
<xsl:preserve-space elements="list-of-element-names"/>
<xsl:strip-space elements="list-of-element-names"/>
<xsl:strip-space elements="list-of-element-names"/>
属性
| 属性 | 值 | 説明 |
|---|---|---|
| elements | list-of-element-names |
必須。空白区切りの要素リストで、空白を保持/削除する要素を指定します。 注意:リストには "*" と "prefix:*" を含めることができ、これによりすべての要素、または特定の名前空間のすべての要素を追加できます。 |
例 1
この例では、title 要素と artist 要素の空白ノードを保持し、country、company、price、year 要素の空白ノードを削除します。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="country company price year" />
<xsl:preserve-space elements="title artist" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd">
<p>
<xsl:value-of select="title" /><br />
<xsl:value-of select="artist" /><br />
<xsl:value-of select="country" /><br />
<xsl:value-of select="company" /><br />
<xsl:value-of select="price" /><br />
<xsl:value-of select="year" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="country company price year" />
<xsl:preserve-space elements="title artist" />
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd">
<p>
<xsl:value-of select="title" /><br />
<xsl:value-of select="artist" /><br />
<xsl:value-of select="country" /><br />
<xsl:value-of select="company" /><br />
<xsl:value-of select="price" /><br />
<xsl:value-of select="year" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
完全な XSLT 要素リファレンス その他の拡張