我有以下XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<html>
<body>
<xsl:for-each select="AdvReqIMailMsg">
<a><xsl:attribute name="href">
http://<xsl:value-of select="BackSideUrl"/>/customerlogin.asp?P=<xsl:value-of select="DynaCalPath"/></xsl:attribute >
Login to View History of This Request
</a>
<br/>
</xsl:for-each>
</body>
</html>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
结果如下:
<a href="
 http://dotnet.dynacal.com/customerlogin.asp?P=DEMO8">
Login to View History of This Request
</a>
为什么

和所有的空格都在那里?我是第一次接触XSLT,我在google上搜索也没有找到我所理解的任何东西。谢谢,肖恩
发布于 2010-10-19 17:26:59
&#A;
是编码的换行符。
它和空格被保留在XSLT中的换行符和空格中。
发布于 2010-10-19 17:41:24
只需使用
<a href="http://{BackSideUrl}/customerlogin.asp?P={DynaCalPath}">
Login to View History of This Request
</a>
这(使用AVT -- Attribute-Value-Templates)既简短又更具可读性。
正如在几乎所有答案中解释的那样,报告的行为的原因是属性href
的值(部分)是由包含NL字符的文本节点构造的。
这些问题是由一种纯粹的人类心理现象引起的:当NL被非空格包围时,我们可以清楚地看到NL,但是当NL在文本块的开头或结尾处时,我们是NL盲的。在请求时显示特殊的“不可见”字符组,如NL和CR,这将是任何XSLT/XML IDE的有用特性。
发布于 2010-10-19 17:39:46
当您混合使用文本和元素节点时,会保留空格。因此,一种解决方案是在开始时避免使用空格(如Bart所示),或者执行以下操作,因为它的格式设置得很好,因此可读性更好:
<xsl:attribute name="href">
<xsl:text>http://</xsl:text>
<xsl:value-of select="BackSideUrl"/>
<xsl:text>/customerlogin.asp?P=</xsl:text>
<xsl:value-of select="DynaCalPath"/>
</xsl:attribute >
https://stackoverflow.com/questions/3970963
复制