防止在 xslt 转换中创建新行

prevent creation new line in xslt transformation

我的源xml文件

<numbers>
    <number>
        one
    </number>
    <number>
        two
    </number>
 <numbers>

我有 xsl 文件可以转换成 html。我想构建这样的文本:

one, two

在输出中。

为此,我使用

<xsl:value-of select="//numbers/number" separator=", "/>

但在输出中我会看到带有新行的文本

one
, 
two

在浏览器中它看起来像 'one , two'(逗号周围有 space)。我想在没有左space.

的情况下获得价值

我用的是saxon he 9.4.

您的 number 元素中有白色-space,包括实际 "one" 文本前后的换行符,这就是被拾取的内容。

由于您使用的是 XSLT2.0,请将您的表达式更改为此以删除文本任何一侧的白色-space

<xsl:value-of select="//numbers/number/normalize-space()" separator=", "/>