XSLT为什么是
 出现在我的hrefs?

Sha*_*awn 6 xml xslt

我有以下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>
Run Code Online (Sandbox Code Playgroud)

结果如下:

<a href="&#xA;                  http://dotnet.dynacal.com/customerlogin.asp?P=DEMO8">
                Login to View History of This Request
              </a>
Run Code Online (Sandbox Code Playgroud)

为什么&#xA;那里有所有的空间?我是XSLT的新手,我的谷歌搜索没有改变我理解的东西.谢谢,肖恩

SLa*_*aks 7

&#A;是一个编码的换行符.

它和空格是从XSLT中的换行符和空格中保留的.


Dim*_*hev 6

只需使用:

<a href="http://{BackSideUrl}/customerlogin.asp?P={DynaCalPath}">
           Login to View History of This Request
</a>
Run Code Online (Sandbox Code Playgroud)

这(使用AVT - 属性 - 值 - 模板)更短,更易读.

几乎所有答案中所解释的,报告行为的原因是属性的值href(部分地)来自包含NL字符的文本节点.

这些问题是由纯粹的人类心理现象引起的:我们清楚地看到NL只要它被非白色空间包围,但是每当NL处于一个文本块的开头或结尾时我们都是NL盲.任何XSLT/XML IDE都可以在请求组中显示特殊的"不可见"字符,例如NL和CR.