在 XSL 中创建空间 ( ) [英] Creating a space ( ) in XSL
问题描述
我试图通过以下方式在 XSL 文档中创建自动间距.
Im trying to create automatic spacing in a XSL document in the following manner.
知道如何解决这个问题吗? Any idea on how I could fix this? 您当前的问题是,虽然 unicode 160 (hex 0xA0) Your immediate problem is that while unicode 160 (hex 0xA0) 使用 Use 然而,对于更大的问题,如何在 XSL 中处理空白,答案很简单:使用 However for your larger problem, how to handle white space in XSL, the answer is simply this: Use 每次包含任何纯文本时,请将其包含在 Every time you include ANY plain text, enclose it in 您至少已经进入了一个大陆,或者如果您幸运的话,您可能已经进入了一个痛苦的国家,因为期望 XML/XSL 保留空白.即使是理解 XSL 到第 n 级的天才仍然会从空白处理中得到县级或至少自治市级的痛苦.(自治市镇级别的痛苦在 XML 规范2.11 行尾处理"中编码,因为其疯狂的设计决定拒绝区分 LF 和 CRLF - 所以没有人可以避免这一点). You are already in for at least a Continent, or possibly if you are lucky a Country of pain, for expecting XML/XSL to conserve whitespace. Even geniuses who understand XSL to the nth degree still get County or at least Borough level pain from whitespace handling. (Borough level pain is encoded in the XML spec, "2.11 End-of-Line Handling" by its insane design decision to refuse to distinguish between LF and CRLF - so nobody can avoid that). 只是为了让您知道会发生什么:这并不容易 - 您可以在没有 Just so you know what to expect: It isn't easy - you can get away without the 错误示例: 右侧示例: 问题是,它们都产生完全相同的输出. The thing is, they both produce exactly the same output. 但其中一个将在未来的某个时候搞砸,是的,可能被尚未出生的人,对方不会. But one of them will be messed up at some point in the future, yes, possibly by someone as yet unborn, the other will not. 简短的解释是:默认情况下忽略仅包含空格的节点(除非您调整选项).所以这是任何仅由 The short-ish explanation is this: Nodes consisting ONLY OF WHITESPACE are ignored by default (unless you tweak the options). So that is anything consisting only of 所以示例 RIGHT 和此之间的区别: So the difference between the Example RIGHT and this: 是一个生成 is that one generates 其中只有一个是您想要的...但任何一个都可能是正确的,具体取决于有效的选项... Only one of which was what you wanted... but any of which might be correct depending on the options in force... 这篇关于在 XSL 中创建空间 (&nbsp;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<td><xsl:value-of select="Name/First"/> <xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text><xsl:value-of select="Name/Last"/> </td>
However, the rendered HTML is of the following form<td>John&nbsp;Grisham</td>
推荐答案
是一个 HTML 实体,但它不是一个 XML实体.
is an HTML entity, it is not an XML entity.  
或  
代替不间断空格. 
or  
for non-breaking-space instead.
.<xsl:text>
.
标签.如果不这样做,下次聪明的文本编辑器重新格式化您的文档时,您将陷入痛苦的境地.<xsl:text> the text goes here </xsl:text>
tags. If you don't you will be in for a world of pain the next time a clever text editor reformats your document.<xsl:text>
标签的情况下逃脱很长一段时间,但如果您接受它,并从一开始就把它们放进去,从长远来看会更容易.<xsl:text>
tags for a surprisingly long time, but if you just accept it, and put them in from the get-go, it will be easier in the long run. <xsl:element name="MyElem">
<xsl:attribute name="fullPath">c:\base\Path\here\<xsl:value-of select="../parent/@relPath"/>\<xsl:value-of select="@fileName">
</xsl:attribute>
</xsl:element>
<xsl:element name="MyElem">
<xsl:attribute name="fullPath">
<xsl:text>c:\base\Path\here\</xsl:text>
<xsl:value-of select="../parent/@relPath"/>
<xsl:text>\</xsl:text>
<xsl:value-of select="@fileName">
</xsl:attribute>
</xsl:element>
CR
、LF
、TAB
和 SPACE
组成的 >
代码> 和 <代码><.由非空白文本、前导和尾随空白组成的节点可能具有折叠"的空白 - 即成功了.CR
, LF
, TAB
and SPACE
between >
and <
. Nodes consisting of non-whitespace text, with leading and trailing whitespace, may have whitespace "folded" - I.e. effed up. <xsl:element name="MyElem">
<xsl:attribute name="fullPath">
c:\base\Path\here\
<xsl:value-of select="../parent/@relPath"/>
\
<xsl:value-of select="@fileName">
</xsl:attribute>
</xsl:element>
<MyElem fullPath="c:\base\Path\here\relative\path\filename.txt"/>
和另一个,取决于 DOM 选项force,生成以下之一:<MyElem fullPath="c:\base\Path\here\relative\path\filename.txt"/>
and the other, depending on the DOM options in force, generates one of these:<MyElem fullPath="c:\base\Path\here\relative\path\filename.txt"/>
<MyElem fullPath="c:\base\Path\here\ relative\path \ filename.txt"/>
<MyElem fullPath="c:\base\Path\here\ relative\path \&10;filename.txt"/>
<MyElem fullPath="c:\base\Path\here\	 relative\path	 \	&10;	filename.txt"/>
登录
关闭