Project

Profile

Help

Bug #5739

open

Space in string in text template not output as element content

Added by Martin Honnen 7 days ago. Updated 6 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
XSLT Conformance
Sprint/Milestone:
Start date:
2022-11-20
Due date:
% Done:

0%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

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

sample1.json (40 Bytes) sample1.json Martin Honnen, 2022-11-20 17:18
sheet1.xsl (516 Bytes) sheet1.xsl Martin Honnen, 2022-11-20 17:18
sheet2.xsl (411 Bytes) sheet2.xsl Martin Honnen, 2022-11-20 17:28
sheet2-saxoncsexport.xsl.sef.json (1.09 KB) sheet2-saxoncsexport.xsl.sef.json Martin Honnen, 2022-11-20 17:37
Actions #1

Updated by Martin Honnen 7 days 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>
Actions #2

Updated by Martin Honnen 6 days 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?

Actions #3

Updated by Martin Honnen 6 days 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 = '&lt;function-result&gt; &lt;/function-result&gt;'"/>
      
   </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 = '&lt;function-result&gt; &lt;/function-result&gt;'"/>
      
   </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