XSLT <xsl:strip-space>
❮ Complete XSLT Element Reference
定義和用法
<xsl:strip-space> 元素用於定義應刪除其中空白字元的元素。
注意: 保留空白字元是預設設定,因此只有在使用 <xsl:strip-space> 元素時才需要使用 <xsl:preserve-space> 元素。
注意: <xsl:preserve-space> 元素和 <xsl:strip-space> 元素是頂層元素。
語法
<xsl:preserve-space elements="list-of-element-names"/>
<xsl:strip-space elements="list-of-element-names"/>
屬性
Attribute | 值 | 描述 |
---|---|---|
元素 | list-of-element-names | 必需。一個由空格分隔的元素名稱列表,將為這些元素保留/刪除空白字元。 注意: 該列表還可以包含“*”和“prefix:*”,以便可以合併所有元素或來自特定名稱空間的所有元素。 |
示例 1
在下面的示例中,我們為 title 和 artist 元素保留空白節點,並刪除 country、company、price 和 year 元素的空白節點。
<?xml version="1.0" encoding="UTF-8"?>
<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>
❮ Complete XSLT Element Reference