XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Yitzhak KhabinskySubject: .NET XslCompileTransform strips newline character in xslt method="text" mode
Author: Yitzhak Khabinsky
Date: 02 Jun 2016 05:00 PM
My Stylus Studio is X15 Release 2 Enterprise Edition, build 1928m.

I am trying to transform an XML file into *.csv text file via XSLT transformation.
In a SS scenario I use the .NET XslCompileTransform processor.
Unfortunately, the output doesn't respect newline character: 
.


input XML file:
<root>
<line>line1</line>
<line>line2</line>
<line>line3</line>
</root>

XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="US-ASCII"/>

<xsl:template match="/">
<xsl:for-each select="root/line">
<xsl:value-of select="."/><xsl:text>;</xsl:text><xsl:text>&#xA;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Output:
line1;line2;line3;

Desired Output:
line1;
line2;
line3;

When I run the XSLT transformation with any other processor, i.e. Saxon, Java built-in, MSXML 6, etc. all of them produce the correct output.




DocumentNewLineHandling.xml
XML file

DocumentNewLineHandling.xslt
XSLT file

Postnext
Yitzhak KhabinskySubject: .NET XslCompileTransform strips newline character in xslt method=
Author: Yitzhak Khabinsky
Date: 02 Jun 2016 05:11 PM
I wrote a small program to test...
It produces the correct output

void Main()
{
const string SOURCEXMLFILE = @"d:\Temp\NewLineHandling.xml";
const string XSLTFILE = @"d:\Temp\NewLineHandling.xslt";
const string OUTPUTXMLFILE = @"d:\Temp\NewLineHandling.csv";

using (XmlReader src = XmlReader.Create(SOURCEXMLFILE))
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XSLTFILE, new XsltSettings(true,true), new XmlUrlResolver());

XmlWriterSettings settings = xslt.OutputSettings.Clone();

// XmlWriterSettings.NewLineHandling Property
// https://msdn.microsoft.com/en-us/library/system.xml.xmlwritersettings.newlinehandling(v=vs.110).aspx
//
//settings.NewLineHandling = NewLineHandling.Replace; // default value

XmlWriter result = XmlWriter.Create(OUTPUTXMLFILE, settings);
xslt.Transform(src, new XsltArgumentList(), result, new XmlUrlResolver());
result.Close();
}

}


Postnext
Ivan PedruzziSubject: .NET XslCompileTransform strips newline character in xslt method=
Author: Ivan Pedruzzi
Date: 02 Jun 2016 05:24 PM
Yitzhak,

The quickest workaround is to change your program to accept 3 parameters so you can run it as custom XSLT processor from Stylus studio

The parameters are

%1 XML input path
%2 XSLT path
%3 output path

If you run such task only from Stylus Studio you way want to look at our converter engines (CSV or TAB) which can emit flat files without coding XSLT



Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Yitzhak KhabinskySubject: .NET XslCompileTransform strips newline character in xslt method=
Author: Yitzhak Khabinsky
Date: 02 Jun 2016 08:27 PM
Hi Ivan

- We use SS as a development environment to create and test XSLTs.
- We use MS SQL Server SSIS XML Task XSLT operation as a production run-time environment. The SSIS XML Task is using .Net XslCompiledTransform API internally.

I hope you would fix SS .Net XslCompiledTransform implementation to resolve the issue we bumped into.

Postnext
Ivan PedruzziSubject: .NET XslCompileTransform strips newline character in xslt method=
Author: Ivan Pedruzzi
Date: 03 Jun 2016 04:34 PM

We have determined that Stylus Studio runs the correct code when invoking XslCompiledTransform, this seems to be a defect in the .NET XmlWriter which merges multiple text node incorrectly.

Changing the XSLT code like the following solves the problem

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" encoding="US-ASCII"/>

<xsl:template match="/">
<xsl:for-each select="books/book">
<xsl:value-of select="concat(title,';','&#xA;')"/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Posttop
Ivan PedruzziSubject: .NET XslCompileTransform strips newline character in xslt method=
Author: Ivan Pedruzzi
Date: 09 Jun 2016 02:59 AM

We have fixed the problem in X16 build 1987e

Ivan Pedruzzi
Stylus Studio Team

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.