A XSLT with a xsl:text
containing a single (or multiple) whitespace(s) is not printing the whitespace(s) in MarkLogic 9.0-9. See the following example:
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"
This returns false. The result is "foobar". I actually expected "foo bar".
I also tried with <xsl:text xml:space="preserve"> </xsl:text>
but this does not work either.
As a workaround I currently use <xsl:value-of select="' '"/>
which works fine but I am wondering if this is a bug? Using the same transformation and document in Saxon prints the whitespaces.
答案 0 :(得分:4)
对于标准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是否支持该声明或某种专有的类似方法来更改元素构造函数中对空格的解析处理。