Project

Profile

Help

Why does HTML output start with a newline?

Added by Martin Honnen 4 months ago

I have run into some oddity it seems with Saxon-JS 2 and html output, both when running with Javascript or when using xslt3 I get a newline before the created HTML document start (e.g. usually the <!DOCTYPE html>):

PS C:\SomePath\saxon-js-2> xslt3 -s:sample2.xml -xsl:.\xml-processing-test1.xsl

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>This is a test</title>
   </head>
   <body>
      <section>
         <h1>This is a test</h1>
         <section>
            <h2>heading</h2>
            <ul>
               <li>foo</li>
               <li>bar</li>
               <li>baz</li>
            </ul>
         </section>
      </section>
   </body>
</html>
<!--Run with Saxon-JS 2.0-->

Files are

<?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:mode on-no-match="shallow-copy"/>
    
    <xsl:template match="/">
        <xsl:next-match/>
        <xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')}</xsl:comment>
    </xsl:template>
    
</xsl:stylesheet>

and input

<?xml version="1.0" encoding="utf-8"?>
<html lang="en">
    <head>
        <title>This is a test</title>
    </head>
    <body>
        <section>
            <h1>This is a test</h1>
            <section>
                <h2>heading</h2>
                <ul>
                    <li>foo</li>
                    <li>bar</li>
                    <li>baz</li>
                </ul>
            </section>
        </section>
    </body>
</html>

If the input is XML not having an html root so that no html serialization is triggered then the result starts directly with the XML declaration, not with a newline.


Replies (1)

    (1-1/1)

    Please register to reply