XSLT And Newline Character Handling
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
XSLT And Newline Character Handling
It is well documented that I cannot create portable XSLT, since different operating systems handle new line characters differently. The XML standard states that an XML parser is required to store only a linefeed character at the end of a line (
). To ensure that my XSLT is portable, I used <xsl:text>
</xsl:text> for new lines as opposed to <xsl:text>
</xsl:text>. This all makes sense to me. When I use oxygen to test out my XSLT, the resulting output shows only linefeed characters for line ends.
I am writing Java code to perform transformations and using XSLT 1.0. I thought that I would have to perform replacements of the 
 to 
. To my surprise, I did not have to do this. The file stream output already had the proper line end characters that Windows expects.
My question is why am I seeing this difference in line end characters for the same XSLT I generated and tested using oxygen?
Thanks.
I am writing Java code to perform transformations and using XSLT 1.0. I thought that I would have to perform replacements of the 
 to 
. To my surprise, I did not have to do this. The file stream output already had the proper line end characters that Windows expects.
My question is why am I seeing this difference in line end characters for the same XSLT I generated and tested using oxygen?
Thanks.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XSLT And Newline Character Handling
Hello Jamil,
It depends on what XSLT processor you're using in your Java code and with what flags.
XSLT processors may format the output with a specific line terminator or the default one of the used platform.
Regards,
Adrian
It depends on what XSLT processor you're using in your Java code and with what flags.
XSLT processors may format the output with a specific line terminator or the default one of the used platform.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 99
- Joined: Thu Oct 23, 2008 6:29 am
Re: XSLT And Newline Character Handling
Hi Adrian. Thanks for your response.
I am using Java 1.7's XSLT processor, and I am not setting any specific options that is adding operating specific line end characters. It very well could be that Java is doing this all on its own to save me time.
I am using a DOMSource as my XML dource document, and a ByteArrayOutputStream for my output. My syntax to do the XSLT transformation is simply:
This is all I have. Something is automatically adding carriage return and line feed characters to line ends.
I am using Java 1.7's XSLT processor, and I am not setting any specific options that is adding operating specific line end characters. It very well could be that Java is doing this all on its own to save me time.
I am using a DOMSource as my XML dource document, and a ByteArrayOutputStream for my output. My syntax to do the XSLT transformation is simply:
Code: Select all
ByteArrayOutputStream outputTarget = null;
DOMSource domSource = createDomSource();
transformer.transform(domSource, outputTarget);
FileOutputStream output = new FileOutputStream (new File("output.txt"));
outputTarget.writeTo(output);
output.close();
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service