Bug #5739
open
Space in string in text template not output as element content
0%
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
Updated by Martin Honnen 10 months ago
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>
Updated by Martin Honnen 10 months ago
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?
Updated by Martin Honnen 10 months ago
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
Please register to edit this issue
Also available in: Atom PDF Tracking page