473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help - I'm losing newline when performing XSL Transform

I'm trying to preserve the newline characters in my transformed XML
(read from a file) to provide a meaningful line number when validation
errors occur. However, my current method which performs an XSL
transform prior to validation is removing all the newlines. The XSL is
simply adding a namespace:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="urn:RegisteredUser-schema">

<!-- This will just set the namespace of the topmost object -->
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:copy-of select="." />
</xsl:template>

</xsl:stylesheet>

The problem is that an input XML string which has newlines goes from:
<user>
<firstname>Joe</firstname>
<lastname>User</lastname>
</user>
to a string without newlines:
<user
xmlns="urn:RegisteredUserschema"><firstname>Joe</firstname><lastname>User</*lastname></user>

So any subsequent validation failure states that an error occurred on
line 1. I would like to be able to preserve the newlines in the
original string representation of the file, so that the error message
displayed to the user is meaningful.
Thanks in advance

Oct 1 '05 #1
7 17185
jjouett said the following on 2005-10-01 23:40 +0200:
I'm trying to preserve the newline characters in my transformed XML
(read from a file) to provide a meaningful line number when validation
errors occur. However, my current method which performs an XSL
transform prior to validation is removing all the newlines. The XSL is
simply adding a namespace:


I'm fairly new to XML and XSL(T), but have you tried adding:

<xsl:output method="xml" indent="yes>

... to your xsl file?

http://www.w3.org/TR/xslt#output

There are also some notes on white space handling for xsl and xml which might be of interest, but I think the indent attribute solves your newline problem:

http://www.w3.org/TR/xslt#strip
http://www.w3.org/TR/REC-xml/#sec-white-space

--
Regards
Harrie
Oct 1 '05 #2
In article <11*********************@g14g2000cwa.googlegroups. com>,
jjouett <jj*****@necam.com> wrote:
However, my current method which performs an XSL
transform prior to validation is removing all the newlines.


Your stylesheet looks ok. What XSLT processor are you using?

-- Richard
Oct 1 '05 #3
That did it! I don't know why I didn't think of that. Thanks to
everyone for their response.

Oct 2 '05 #4
That did it! I don't know why I didn't think of that. Thanks to
everyone for their response.

Oct 2 '05 #5
Harrie said the following on 2005-10-02 00:16 +0200:
<xsl:output method="xml" indent="yes>


To correct myself, I forgot the closing double quotes at the end, so it should read:

<xsl:output method="xml" indent="yes">

--
Regards
Harrie
Oct 2 '05 #6
jjouett said the following on 2005-10-02 04:45 +0200:
That did it! I don't know why I didn't think of that. Thanks to
everyone for their response.


I had the same problem some time ago, therefor I remembered that it defaults to not indent.

I'm not sure why it only preserves newlines and not indentation when <xsl:output method="html" />, or maybe that's just my xml processor (xsltproc).

--
Regards
Harrie
Oct 2 '05 #7
Harrie said the following on 2005-10-02 15:07 +0200:
Harrie said the following on 2005-10-02 00:16 +0200:

To correct myself, I forgot the closing double quotes at the end, so it
should read:

<xsl:output method="xml" indent="yes">


Bugger, it's an empty element, it should read:

<xsl:output method="xml" indent="yes" />

I'll drink some more coffee now ..

--
Regards
Harrie
Oct 2 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gordon Scott | last post by:
Hi All, I've got a problem I'm seeing when trying to use the struct module to send data to a different machine. Actually I'm making a condensed file that gets transferred to and read on a BREW...
5
by: Danny Anderson | last post by:
Hola- I didn't get any responses on a previous post, so I am trying to reword my problem and post compile-able code that exhibits the behavior I am describing. On the second iteration of the...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
4
by: dkacher | last post by:
Hello - I'm looking for a way to retain newlines when using XSL to copy the content of an XML attribute. I have this XML input: <?xml version="1.0"?> <A > <B x = "stuff" y = "line 1 line 2"...
3
by: mike | last post by:
Hi all, I am using StreamWriter class to save string var into html file but somehow when I open the html file all formats are lost. I want to keep all formats(spaces, newline and so on)For...
5
by: Ward Germonpré | last post by:
Hi, From a PHP backend I generate a javascript array like this : bevestigingen = [{id:'47',leverancier:'VELUX',depot:'KNO',klant:'',werf:'',referentie:'Ro els',producten:'DKL U04 1100 1st...
2
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example,...
3
by: Simon Brooke | last post by:
As various people will have noticed, I've been having a lot of trouble with XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and it worked well enough for me, so it's been...
23
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.