XSLT <xsl:preserve-space>および<xsl:strip-space>エレメント

定義と使用法

<xsl:preserve-space>エレメントは空白を保持するエレメントを定義するために使用されます。

<xsl:strip-space>エレメントは空白を削除するエレメントを定義するために使用されます。

注記:空白の保持はデフォルトの設定であり、<xsl:strip-space>エレメントを使用する場合にのみ<xsl:preserve-space>エレメントを使用する必要があります。

注記:<xsl:preserve-space>および<xsl:strip-space>エレメントはトップレベルエレメント(top-level element)です。

文法

<xsl:preserve-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>