Project

Profile

Help

Bug #4596

closed

XML output has empty line between XML declaration and root element

Added by Martin Honnen over 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>

Please register to edit this issue

Also available in: Atom PDF Tracking page