Project

Profile

Help

How to use saxon:newline serialization option to have CRLF line endings

Added by Martin Honnen about 6 years ago

Based on http://saxonica.com/html/documentation/extensions/output-extras/serialization-parameters.html saying that you can specify the additional serialization parameters on xsl:output I tried to run

<?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:saxon="http://saxon.sf.net/"
	exclude-result-prefixes="#all"
	version="3.0">
	
	<xsl:output method="text" saxon:newline="&#13;&#10;"/>
	
	<xsl:template match="/" name="xsl:initial-template">
		<xsl:value-of select="(1 to 5)!('Line ' || . || '.')" separator="&#10;"/>
	</xsl:template>
	
</xsl:stylesheet>

from the command line (-it -xsl:sheet.xsl) with Saxon-EE 9.8.0.12J and I get the output in the console

Line 1.Line 2.Line 3.Line 4.Line 5.

When I direct the output to a file with e.g. -it -xsl:sheet.xsl -o:result.txt the file opened in JEdit also shows only one line

Line 1.Line 2.Line 3.Line 4.Line 5.

As the documentation literally says

Default value x10. Defines the string that is used by the text output method to represent a newline. The Windows line ending x0Cx0A (CRLF) may sometimes be preferred to the default of a single newline character.

I then tried <xsl:output method="text" saxon:newline="x0Cx0A"/> but that then literally outputs Line 1.x0Cx0ALine 2.x0Cx0ALine 3.x0Cx0ALine 4.x0Cx0ALine 5..

So how does one use saxon:newline to get the Windows CRLF line ending with output method text?


Replies (2)

RE: How to use saxon:newline serialization option to have CRLF line endings - Added by Michael Kay about 6 years ago

I think this will work with 9.8 as issued:

<xsl:param name="newline" select="'&#xd;&#xa;'"/>
  
  <xsl:template match="/" name="xsl:initial-template">
    <xsl:result-document method="text" saxon:newline="{$newline}">
      <xsl:value-of select="(1 to 5)!('Line ' || . || '.')" separator="&#xa;"/>
    </xsl:result-document>
  </xsl:template>
    (1-2/2)

    Please register to reply