您现在的位置: 365建站网 > 建站教程 > XSLT 教程 > XSLT <xsl:preserve-space> 和 <xsl:strip-space> 元素

XSLT <xsl:preserve-space> 和 <xsl:strip-space> 元素

此节有 203 人学习过     参与评论

定义和用法

<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>

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

您可能感兴趣的文章:

发表评论 (203人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------
XSLT 教程目录

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号