Project

Profile

Help

Bug #4596

closed

XML output has empty line between XML declaration and root element

Added by Martin Honnen almost 4 years ago. Updated over 3 years ago.

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

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
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>
Actions #1

Updated by Debbie Lockett almost 4 years ago

  • Assignee set to Debbie Lockett
Actions #2

Updated by Debbie Lockett almost 4 years ago

  • Category set to Serialization

Thanks for logging these serialization issues. I will investigate!

Actions #3

Updated by Debbie Lockett almost 4 years 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).

Actions #4

Updated by Debbie Lockett almost 4 years 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).

Actions #5

Updated by Jamie Peabody over 3 years ago

Thank you for saxon-js - we're evaluating it for use in https://www.npmjs.com/package/@axway/api-builder-plugin-fn-xslt. It is exciting to be able to do XSLT in node.js. We noticed that your release notes have not been updated since 2.0.0 https://www.saxonica.com/saxon-js/release-notes.xml. This issue still persists in saxon-js@2.0.3, so appears to not be resolved.

Actions #6

Updated by Martin Honnen over 3 years ago

My understanding (as just another Saxon-JS user) is that 2.0.3 was simply released to updated a used package due to security fixes.

Actions #7

Updated by Community Admin over 3 years ago

  • Applies to JS Branch 2 added
  • Applies to JS Branch deleted (2.0)
Actions #8

Updated by Community Admin over 3 years ago

  • Fix Committed on JS Branch 2 added
  • Fix Committed on JS Branch deleted (2.0)
Actions #9

Updated by Debbie Lockett over 3 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 2.1

Bug fix applied in the Saxon-JS 2.1 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page