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>