XSL 文本转换中的空格



具有包含单个(或多个(空格的xsl:text的 XSLT 不会打印 MarkLogic 9.0-9 中的空格。请参阅以下示例:

xquery version "1.0-ml";
let $doc := 
  <doc>
    <foo>foo</foo>
    <bar>bar</bar>
  </doc>
let $xsl :=
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
      <xsl:output method="text" omit-xml-declaration="yes" indent="no" />
      <xsl:template match="doc">
          <xsl:value-of select="foo"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="bar"/>
      </xsl:template>
  </xsl:stylesheet>
return xdmp:xslt-eval($xsl, $doc) = "foo bar"

这将返回 false。结果是"foobar"。我实际上期待"foo bar"。我也尝试过<xsl:text xml:space="preserve"> </xsl:text>但这也不起作用。

作为解决方法,我目前使用<xsl:value-of select="' '"/>它工作正常,但我想知道这是否是一个错误?在 Saxon 中使用相同的转换和文档将打印空格。

对于标准的XQuery,你应该得到你想要的

declare boundary-space preserve;

在查询日志中,请参阅 https://www.w3.org/TR/xquery-31/#id-boundary-space-decls 和 https://www.w3.org/TR/xquery-31/#id-whitespace。

例子是 https://xqueryfiddle.liberty-development.net/eiQZDbq/4 做

declare boundary-space preserve;
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method 'text';

let $doc := 
  <doc>
    <foo>foo</foo>
    <bar>bar</bar>
  </doc>
let $xsl :=
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
      <xsl:output method="text" omit-xml-declaration="yes" indent="no" />
      <xsl:template match="doc">
          <xsl:value-of select="foo"/>
          <xsl:text> </xsl:text>
          <xsl:value-of select="bar"/>
      </xsl:template>
  </xsl:stylesheet>
return transform(map { 'source-node' : $doc, 'stylesheet-node' : $xsl })?output 

返回foo bar而 https://xqueryfiddle.liberty-development.net/eiQZDbq/2 没有该声明返回foobar

我还没有检查 Marklogic 是否支持该声明或一些专有的类似方法来更改元素构造函数中空格的解析处理。

最新更新