难道《无废话XML》写错了??!!请大家帮忙看看,给分

hackerning 2002-04-22 06:09:47
书里说XML对于空格是不忽略的,有多少就显示多少,而且不需要加什么额外的属性,因为他是XML的一个标准,但事实上我试了一下,结果和普通的HTML没区别啊,
对于空格还是忽略了啊,为什么,有谁能解释一下吗,立刻给分的!!
...全文
48 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2002-04-22
  • 打赏
  • 举报
回复
Example of <xsl:preserve-space> and <xsl:strip-space>
You can use the <xsl:preserve-space> and <xsl:strip-space> elements to preserve and strip white space from XML documents. The following strippreserve.xml document contains <code> and <block> elements that have white space in the form of tabs, spaces, and newline characters. The strippreserve.xsl style sheet is applied to the strippreserve.xml document to retain white space within all <code> elements and to strip it from all the block elements.

In the strippreserve.xml document, the first <code> element and first <block> element contain exactly the same amount and kind of white space (a single space), as do the second <code> and <block> elements. However, the second <code> and second <block> elements also contain the phrase "Some text" among the white space. For the strippreserve.xml document, the <?xml-stylesheet type="text/xsl" href="strippreserve.xsl" ?> instruction is included to apply the strippreserve.xsl style sheet to the strippreserve.xml document. When applied, the strippreserve.xsl style sheet causes the <code> elements to retain white space-only content and the <block> elements to lose white space-only content.

Example
The strippreserve.xsl style sheet below does the following.

Preserves the extraneous white space in the <code> elements.
Strips the extraneous white space from the <block> elements.
Encloses the content of each <code> and <block> element in square brackets, [ ].
Provides a numbered label for each <code> or <block> using the XSL Transformations (XSLT) position() function.
Using the XML Path Language (XPath) translate() function, converts "invisible" white space to a visible character, one character at a time. This enables you to "see" the specific white characters in the <code> and <block> elements.
Each space character appears in the result tree as a hyphen (-).

Each newline character appears in the result tree as the letter "N."

Each carriage return appears in the result tree as the letter "R."

Each tab appears in the result tree as the letter "T."

The first <code> element contains a single space, denoted by the hyphen in the [ ] characters. The first <block> element also contains a single space in the source document. However, the <xsl:strip-space> setting has caused this space to be removed from the result tree.

In the second <code> and <block> elements, no white space has been removed. If an element has any non-white space content, white space will not be stripped even if <xsl:strip-space> is set for that element.

Note This represents a "pure XSLT" approach to the stripping and retention of white space. You can also strip or retain white space by manipulating the Document Object Model (DOM). For more information about this approach, see White Space and the DOM.
XML File (strippreserve.xml)
Copy this text to a file, then find and replace each "tabhere" by a tab (press the Tab key).

<?xml-stylesheet type="text/xsl" href="strippreserve.xsl" ?>
<document>
<block> </block>
<block>
tabhere
Some texttabhere
tabhere
tabhere</block>
<code> </code>
<code>
tabhere
Some texttabhere
tabhere
tabhere</code>
</document>
XSLT File (strippreserve.xsl)
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- Retain white space within all <code> elements -->
<xsl:preserve-space elements="code"/>
<!-- ... but strip it from all <block> elements -->
<xsl:strip-space elements="block"/>

<xsl:template match="/">
<html>
<head><title>Test: Stripping/Preserving White Space</title></head>
<body>
<h4>Code blocks:</h4>
<!-- <pre> element forces all output characters to be same width -->
<pre>
<!-- Use translate() XPath function to convert white-space
characters to "visible" form. -->
<xsl:for-each select="//code">
"Code" #<xsl:value-of select="position()"/>: [<xsl:value-of select="translate(.,' ','-NRT')"/>]<br/>
</xsl:for-each>
</pre>
<h4>Normalized blocks:</h4>
<pre>
<xsl:for-each select="//block">
"Block" #<xsl:value-of select="position()"/>: [<xsl:value-of select="translate(.,' ','-NRT')"/>]<br/>
</xsl:for-each>
</pre>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
Formatted Output
Code blocks:

"Code" #1: [-]

"Code" #2: [NTNSome-textTNTNT]

Normalized blocks:

"Block" #1: []

"Block" #2: [NTNSome-texttabhereNTNT]

Processor Output
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<title>Test: Stripping/Preserving White Space</title></head>
<body>
<h4>Code blocks:</h4>
<pre>
"Code" #1: [-]<br>
"Code" #2: [NTNSome-textTNTNT]<br></pre>
<h4>Normalized blocks:</h4>
<pre>
"Block" #1: []<br>
"Block" #2: [NTNSome-textTNTNT]<br></pre>
</body>
</html>
孟子E章 2002-04-22
  • 打赏
  • 举报
回复
Preserving or Stripping White Space
XSL Transformations (XSLT) can distinguish nodes that contain white space intermingled with other characters. The white space is considered inseparable from the other text in the node.

For nodes that contain nothing but white space, the <xsl:preserve-space> and <xsl:strip-space> elements handle how the nodes are output.

Preserving White Space with <xsl:preserve-space>
The <xsl:preserve-space> element provides a list of those elements in the source document where white space must be preserved on output. <xsl:preserve-space> is always an empty, top-level element, for example, a child of the <xsl:stylesheet> element in an XSLT style sheet.

The following is the general syntax.

<xsl:preserve-space elements="elem1 elem2..." />
elem1 and elem2 are the names of all elements (without the enclosing < and > delimiters) whose white space must be preserved.

You can specify all of the elements in the source document with the asterisk operator ("*").

<xsl:preserve-space elements="*" />
Because all of the content of an XML document is, by default, preserved, <xsl:preserve-space> is useful only in cases in which you have used <xsl:strip-space> to override the default behavior; in such cases, use <xsl:preserve-space> to identify exceptions to the explicit stripping of white space.

Note The Microsoft® XSLT processor will process all of a document's white space only if the preserveWhiteSpace property has been set to True prior to loading the document into the DOM. For more information, see How the MSXML Processor Parses White Space.
Removing White Space with <xsl:strip-space>
The <xsl:strip-space> element provides a list of those elements in the source document in which content must be removed from the output tree. <xsl:strip-space> is an empty, top-level element.

The following is the general syntax.

<xsl:strip-space elements="elem1 elem2..." />
elem1 and elem2 are the names of all elements (without the enclosing < and > delimiters) whose white space must be removed.

You can specify all of the elements in the source document with the asterisk operator ("*").

<xsl:strip-space elements="*" />
If an element appears in both an <xsl:strip-space> and <xsl:preserve-space> list, the last specification applies. Therefore, a typical sequence of these two elements in an XSLT style sheet is as follows.

<xsl:strip-space elements="*" />
<xsl:preserve-space elements="elem1 elem2..." />
If this order were reversed, the explicit "preserve" settings for elem1, elem2, and so on would be overridden by the global "strip" setting.
wangwenyou 2002-04-22
  • 打赏
  • 举报
回复
将你的styleSheet的xsl:space属性的值设为preserved
这款名为 Total Uninstall (中文名:完美卸载)的软件似乎早已名闻于世,只是一直未曾使用过。刚刚研究了半天,总算基本全部搞懂了,把自己摸索学习到的享出来。当然首先最关心的还是Total Uninstall 6.x的注册问题,因为它并不是免费软件,在此提供可用注册码,并且辅以破解方法,亲测完美!另外,遇到“注册失败:强制网络访问”的问题也解决了。   Total Uninstall 目前最新版本为6.2.2,它是一款非常优秀的软件卸载工具,但是说实话,本人从来不用第三方工具来卸载系统内的软件或程序,都是用软件本身自带的卸载程序或者Windows控制面板里的“程序和功能”。直到今天早上试用了Total Uninstall,发现真是好用,真的是完全彻底卸载!不留任何垃圾文件,强烈推荐!但是从今天的测试来看发现它还是有小BUG的,暂且不讨论它的使用方法和技巧,这部份内容会另外单独发文,本文主要讲解如何安装与注册。   去官方看了下,对它的简介如下: 1、让卸载任何程序删除变得更加容易。准确的析安装的程序并完全卸载它们。“安装程序”模块的总卸载安装的程序进行析,并创建安装日志。这是用来做一个完整的帮助下,即使没有提供标准卸载从添加删除程序卸载。 2、可监视新安装的程序。“监控程序”模块,它可以监视到你的系统中安装一个新的程序所做的任何更改。它可以让你执行一个完整的卸载,而不必依赖于所提供的添加删除程序,它可以给后面的文件或更改。   最新版为6.2.2,不过可惜还用不了,因为破解是针对上一个版本6.2.1的,不过没什么。我看了新版本的更新内容,一是增加俄罗斯,波兰和印度尼西亚的语言支持;二是改进析安装的程序;三是改进清洁扫描。 Total Uninstall 6 注册开始…… 以上的基本都是废话,你可以无视,现在正式开始破解注册。 1、下载。 下载地址在文章最后面,保证官方原版,自带简体中文。 2、安装。 这里千万要注意,一定要在断网的情况下安装!!可以学我一样,暂时把网络连接禁用。安装过程没什么好讲的,一路Next。 3、注册。 保证断网状态,运行程序,点击菜单栏“帮助”-“注册”, 注册名:随便取,别用中文就行。 注册码:59552RW-OP0BF01-MC3ACYR7-SFU36DYH-OBPZLFFM-IW6XZTXX-7IYCYAQU-ARCIUONY-72DVI7RZ-X5M2Y6R4-3PQFCCGR-AIKGC7XB-AZY7IZAZ-UWS6NAFT-USDSYWEA-4KYAIBJH 提示感谢您注册,成功了!如下图: 但不要以为就这么简单,否则也不用写方法了,关键在下面。 4、禁止自动升级。 如果就像以上所述,等你开网后程序会自动更新,破解将失效。所以想做到永久免费使用它,必须关闭它的自动升级。打开“工具”-“选项”,来到“常规设置”,郁闷,“检查更新方式”和“频率”都是灰色不可选的,并且自动设成了自动升级和每天。 这也不难理解,官方总有它的措施。所以关键就在这里了:如何屏蔽它联网更新。我看到网上有方法是修改Program Options.xml文件,还有利用防火墙阻止Tu.exe访问网络的。行不行我不知道,没有去试,但是iHackSoft.com有个更简单的方法提供给大家。 下载包里我放了一个名为“Total Uninstall 6.2.1设置”的小程序,退出Total Uninstall,将它拖到安装目录里执行,直接点击“更改联网配置”,会提示成功。此时重新打开Total Uninstall,发现语言变成了英文。去“工具-选项-界面-语言”重新设置成简体中文即可。破解完成,现在可以重新连网了。 此程序的原理我没有猜错的话就是上述的手工修改配置文件,有兴趣的可以了解一下: 用记事本打开Program Options.xml文件, XP:C:\Documents and Settings\All Users\Application Data\Martau\Total Uninstall 6\Program Options.xml Windows 7:C:\ProgramData\Martau\Total Uninstall 6\Program Options.xml 在文件中搜索“RegName”和“RegKey”,将用户名和注册码末尾3位字母随意修改一个(如把iHackSoft.com改成了iHackSoft.cn,注册码最后的字母H改成了W等)。这样就可以不用设置防火墙拦截了,运行Total Uninstall联网也没有任何问题。 注意事项 1、运行Total Uninstall 6.2设置小程序后,原来注册时使用的用户名变成了every kafan,此时不要傻乎乎地重新键入任意用户名和上面的注册码进行注册,我试了,会提示错误,注册失败:强制网络访问。如果真心要修改用户名,那就进上述的Program Options.xml文件修改RegName,我刚试了,没有问题。 2、此方法适用于没有安装过Total Uninstall的电脑,像我本机就不行了,因为我为了测试做了上面的操作导致注册失败过,之后无论我怎么卸载掉重新安装和注册,都不行了。它是以什么信息来标识每台机器,尚不清楚,待进一步探究。 来源:http://www.ihacksoft.com/total-uninstall-6.html 笔者加了注册失败的解决办法

8,909

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧