Symphony CMS中的奇数XSL输出

acr*_*eek 1 xslt xpath symphony-cms

我在Symphony CMS中尝试返回这样的文章图像.

<img src="{$workspace}/uploads/{/data/news-articles/entry/image-thumbnail}"/>
Run Code Online (Sandbox Code Playgroud)

输出看起来像这样

<img src="/workspace/uploads/%0A%09%09%09%09penuts_thumb.png%0A%09%09%09%09%0A%09%09%09">
Run Code Online (Sandbox Code Playgroud)

如果我只是尝试返回节点值

<xsl:value-of select="image-thumbnail" />
Run Code Online (Sandbox Code Playgroud)

输出看起来正确

penuts_thumb.png
Run Code Online (Sandbox Code Playgroud)

有关为什么我得到所有多余角色的想法?

Dim*_*hev 5

Output looks correct
Run Code Online (Sandbox Code Playgroud)

不,它只是"看起来正确",因为浏览器会忽略空白字符.

会发生什么是字符串"penuts_thumb.png"被空格包围.当这个空格被序列化为src属性值的一部分时,它被编码(规范化) - 这就是你看到%0A(换行代码)anf %09(tab的代码)的原因.

此转换有助于准确查看每种情况下生成的内容:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" indent="yes"/>
 <xsl:variable name="workspace" select="'/workspace'"/>


 <xsl:template match="/">
     <img src="{$workspace}/uploads/{/data/news-articles/entry/image-thumbnail}"/>
     ===========
     <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="entry">
  "<xsl:value-of select="image-thumbnail"/>"
 </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

应用于此XML文档时:

<data>
 <news-articles>
  <entry>
    <image-thumbnail>
                     penuts_thumb.png
    </image-thumbnail>
  </entry>
 </news-articles>
</data>
Run Code Online (Sandbox Code Playgroud)

产生这个输出:

<img src="/workspace/uploads/%0A                     penuts_thumb.png%0A    ">
     ===========



"
penuts_thumb.png
    "
Run Code Online (Sandbox Code Playgroud)

正如我们在第二种情况下看到的那样(感谢引号),字符串"penuts_thumb.png"也被很多空白字符所包围.

方案:

normalize-space()以这种方式使用该功能:

<img src=
"{$workspace}/uploads/{normalize-space(/data/news-articles/entry/image-thumbnail)}"/>
Run Code Online (Sandbox Code Playgroud)