473,804 Members | 3,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns="urn:Regi steredUser-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>Jo e</firstname>
<lastname>Use r</lastname>
</user>
to a string without newlines:
<user
xmlns="urn:Regi steredUserschem a"><firstname>J oe</firstname><last name>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 17301
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************ *********@g14g2 000cwa.googlegr oups.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
3650
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 enabled cell-phone, essentially I'm trying to format content as if it were being streamed over a socket. So I am trying to write a string by first sending a two-byte length of the
5
1895
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 loop below, the file opened is the default (which in this case is ".csv", which makes a 'hidden' file for Linux folk). The step that prompts for a file name step is skipped completely. Why? Is this a cin issue or does it have something to do with...
1
3726
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
4
1777
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" /> </A>
3
4147
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 example, I have sFunc in below format(newline, spaces ...) ----------sFunc ---------------- Function ABC(byval a as integer) as integer If a > 0 then x = 1
5
2957
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 DKL U04 1705 1st ... The problem is that the 'producten' field contains data from a textarea
2
1974
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, either C# or VB.NET, that I can try. Thank You Very Much,
3
4245
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 little changed since. However, it works only with an obsolete version of Saxon (6.2.2 I think), and it has a number of small bugs; and I've at last got to the point where I need to fix it. And I'm finding it, frankly, absurdly frustrating and...
23
2537
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) return s def descrambleLine(line):
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10320
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.