Project

Profile

Help

Bug #4596

XML output has empty line between XML declaration and root element

Added by Martin Honnen 27 days ago. Updated 4 days ago.

Status:
Resolved
Priority:
Low
Category:
Serialization
Sprint/Milestone:
-
Start date:
2020-06-16
Due date:
% Done:

0%

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

Description

I have found another oddity with Saxon-JS 2's serializer, at least in some case it outputs an empty line between the XML declaration and the root element.

Example XSLT is:

<?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" exclude-result-prefixes="#all" version="3.0">

    <xsl:param name="max" as="xs:integer" select="10"/>

    <xsl:mode on-no-match="shallow-copy" use-accumulators="#all" streamable="yes"/>

    <xsl:output method="xml" indent="yes"/>

    <xsl:accumulator name="window" as="item()*" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="root" select="(0, true())"/>
        <xsl:accumulator-rule match="root/row"
            select="
                let $val := xs:integer(@val),
                    $sum := $value[1],
                    $window-start := $value[2],
                    $current-sum := $sum + $val
                return
                    if ($current-sum gt $max)
                    then
                        ($val, true())
                    else
                        ($current-sum, false())"
        />
    </xsl:accumulator>

    <xsl:template match="root">
        <xsl:copy>
            <xsl:for-each-group select="row"
                group-starting-with="*[accumulator-before('window')[2]]">
                <grouped>
                    <xsl:apply-templates select="current-group()"/>
                </grouped>
            </xsl:for-each-group>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

Example XML is:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <row id="AAA" val="2"/>
    <row id="BBB" val="3"/>
    <row id="CCC" val="1"/>
    <row id="DDD" val="4"/>
    <row id="EEE" val="6"/>
    <row id="FFF" val="3"/>
    <row id="GGG" val="6"/>
    <row id="HHH" val="8"/>
    <row id="III" val="3"/>
    <row id="JJJ" val="4"/>
    <row id="KKK" val="2"/>
    <row id="LLL" val="1"/>
</root>

Running this with xslt3 on Windows 10 and Node 12 gives

PS C:\Users\SomePath\group-adjacent> xslt3  -s:.\adjacent-sum-input1.xml -xsl:.\accumulate-group-starting-with1.xsl
<?xml version="1.0" encoding="UTF-8"?>

<root>
   <grouped>
      <row id="AAA" val="2"/>
      <row id="BBB" val="3"/>
      <row id="CCC" val="1"/>
      <row id="DDD" val="4"/>
   </grouped>
   <grouped>
      <row id="EEE" val="6"/>
      <row id="FFF" val="3"/>
   </grouped>
   <grouped>
      <row id="GGG" val="6"/>
   </grouped>
   <grouped>
      <row id="HHH" val="8"/>
   </grouped>
   <grouped>
      <row id="III" val="3"/>
      <row id="JJJ" val="4"/>
      <row id="KKK" val="2"/>
      <row id="LLL" val="1"/>
   </grouped>
</root>

History

#1 Updated by Debbie Lockett 27 days ago

  • Assignee set to Debbie Lockett

#2 Updated by Debbie Lockett 25 days ago

  • Category set to Serialization

Thanks for logging these serialization issues. I will investigate!

#3 Updated by Debbie Lockett 5 days ago

  • Status changed from New to In Progress
  • Fix Committed on JS Branch 2.0 added

This problem with the additional blank line between an XML declaration and the root element, and bug #4592 (where there is a blank line before the document type declaration in a HTML document) are caused by the same issue in the code.

A patch has been committed in the Serializer pipeline: namely that the afterEndTag of the XMLIndenter should be initialised as false not true. This is to avoid the indent call (which adds a newline) before writing the (doctype declaration and) start tag for the root element in the first call on startElement.

Tests to be committed, but I'm still figuring out where. Indentation is implementation dependent, so XSLT 3.0 test suite tests are not really suitable for checking indentation and whitespace. We probably need to add an XSLT3extra test suite for Saxon-JS (QT3extra has recently been added).

#4 Updated by Debbie Lockett 4 days ago

  • Status changed from In Progress to Resolved

Serialization tests added in Mocha Saxon-JS API test set: html-002 (bug #4592) and xml-003 (bug #4596).

Please register to edit this issue

Also available in: Atom PDF Tracking page