Bug #5739
closed
Space in string in text template not output as element content
Category:
XSLT Conformance
Applies to JS Branch:
2, Trunk
Fix Committed on JS Branch:
2, Trunk
Description
Using xslt3
of SaxonJS 2.5 from the command line with e.g. -json:sample1.json -xsl:sheet1.xsl
, I find that the explicit blank for the third element is not output/serialized i.e. with xslt3
the (wrong) output is
<?xml version="1.0" encoding="UTF-8"?>
<Details>
<name indexarray="0">1</name>
<name indexarray="1">2</name>
<name indexarray="2"/>
</Details>
while SaxonCS gives the right output
<?xml version="1.0" encoding="UTF-8"?>
<Details>
<name indexarray="0">1</name>
<name indexarray="1">2</name>
<name indexarray="2"> </name>
</Details>
Even simpler test case -it -xsl:sheet2.xsl
gives
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Text1> </Text1>
<Text2/>
</Test>
with SaxonCS but misses the space with SaxonJS:
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Text1/>
<Text2/>
</Test>
Files
Even with a SaxonCS compiled SEF xslt3
doesn't output the space character e.g. xslt3 -it -xsl:sheet2-saxoncsexport.xsl.sef.json
gives
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Text1/>
<Text2/>
</Test>
Interestingly enough SaxonJS 2.5/xslt3 manages to output the space with xsl:output indent="no"
e.g.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:output indent="no"/>
<xsl:template name="xsl:initial-template">
<Test>
<Text1>{' '}</Text1>
<Text2> </Text2>
</Test>
</xsl:template>
</xsl:stylesheet>
does give me the wanted result <?xml version="1.0" encoding="UTF-8"?><Test><Text1> </Text1><Text2/></Test>
.
So is the serializer somehow crunching the space?
Even the serialize
function if used with the indent
true option eats up the space so the following XSpec
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:mf="http://example.com/mf"
stylesheet="text-value-template-and-serialization.xsl">
<x:scenario label="function mf:test2() returns element with space">
<x:call function="mf:test2"/>
<x:expect label="Element contains space" test="$x:result = ' '"/>
</x:scenario>
<x:scenario label="function mf:serialize-test2() without indentation returns element with space">
<x:call function="mf:serialize-test2">
<x:param select="false()"/>
</x:call>
<x:expect label="Element contains space" test="$x:result = '<function-result> </function-result>'"/>
</x:scenario>
<x:scenario label="function mf:serialize-test2() with indentation returns element with space">
<x:call function="mf:serialize-test2">
<x:param select="true()"/>
</x:call>
<x:expect label="Element contains space" test="$x:result = '<function-result> </function-result>'"/>
</x:scenario>
</x:description>
with XSLT being
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all"
expand-text="yes"
version="3.0">
<xsl:function name="mf:test2" as="element()">
<function-result>{' '}</function-result>
</xsl:function>
<xsl:function name="mf:serialize-test2" as="xs:string">
<xsl:param name="indent" as="xs:boolean"/>
<xsl:sequence select="mf:test2() => serialize(map { 'method' : 'xml', 'indent' : $indent })"/>
</xsl:function>
</xsl:stylesheet>
fails the last scenario x:scenario label="function mf:serialize-test2() with indentation returns element with space"
with SaxonJS 2.5
- Status changed from New to Resolved
- Applies to JS Branch Trunk added
- Fix Committed on JS Branch 2, Trunk added
The serialization specification gives a processor wide latitude when implementing the indent option:
If the indent parameter has one of the values yes, true or 1, the serializer MAY output whitespace characters in addition to the whitespace characters in the instance of the data model. It MAY also elide from the output whitespace characters that occurred in the instance of the data model or replace such whitespace characters with other whitespace characters.
I don't think the SaxonJS behavior could be described as non-conformant, but the fact that it differs from SaxonJ may be confusing.
I wouldn't be willing to commit to making sure that SaxonJS and SaxonJ indented serializations were always the same, but the fix for this particular case was straightforward.
FWIW, I think it probably comes under the rule "Whitespace characters SHOULD NOT be added, elided or replaced in places where the characters would constitute significant whitespace" - though the rule is far from clear, and in any case is not a MUST NOT.
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in JS Release set to SaxonJS 2.6
Bug fix applied in the SaxonJS 2.6 maintenance release.
Please register to edit this issue
Also available in: Atom
PDF
Tracking page