Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2005, 11:18 AM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default newbie help - inserting new line character

I am inheriting support for an app that has XSLT in it, and I have not yet had any XSLT experience or training. I'm trying to do "a quick fix" and have been fumbling around. I've been introduced to the XSLT document but understand very little of the constructs and language.

I need to insert a new line character into the output of our XSLT, which is another XML document. I've tried inserting it via the code below but it's not working. I just changed it to add the '\n' character (I'm a Java developer), the larger structure with the variable and 'value-of's were already there.

I did some searching for this and found one site that suggested doing

Code:
<xsl:text>#xa;</xsl:text>
to output a newline character, but I don't know how to integrate that into the 'xsl:value-of' code below, which appears to be used to build a the comments variable.

What they're doing is dumping a bunch of excess data into this 'Comments' field, which is displayed in a <textArea> at some point, and they want it formatted better, with new lines for each new data field that was dumped into this Comments area. I know it sounds stupid; there are many kludgy, stupid requirements about this project it's driving me crazy.

Code:
<xsl:variable name="CommentsVar">
    <xsl:value-of select="'Reported by the agent..'"/>
    <xsl:value-of select="'\n'"/>
I'd appreciate any help. Thanks
 
Old September 6th, 2005, 11:27 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It depends somewhat on where you are trying to put a newline but
Code:
<xsl:value-of select="'Reported by the agent..#xa;'"/>
or
Code:
]<xsl:value-of select="'Reported by the agent..#xd;'"/>
may work.

--

Joe (Microsoft MVP - XML)
 
Old September 6th, 2005, 12:24 PM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply. What is the difference between the '#xa' and '#xd'?
 
Old September 6th, 2005, 01:52 PM
Registered User
 
Join Date: Sep 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've tried both of these strings, the '#xd;' and '#xa;'. They both came through as that on the XML instead of a new line. I mean I saw the same string ('#xd;') in the output XML, and it didn't appear to render as a new line. Is that what was supposed to happen?

 
Old September 7th, 2005, 01:53 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

My post ran foul of the forum parser. The two entities are (without the dashes for real use:
Code:
&-#-x-a; (carriage return)
&-#-x-d; (new line)
If I understand correctly an XML parser automatically converts all continuous combinations of these to a single new line character whilst parsing so either one should work. If your output is HTML though neither will work as HTML needs
Code:
<br>
--

Joe (Microsoft MVP - XML)
 
Old September 7th, 2005, 07:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Not quite correct - xA is newline (line feed), xD is carriage return. An XML parser turns *real* carriage returns or CRLF pairs into single newlines, but not CRs or LFs written as entity references.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML parsing: line 1, character 38, unable to switc prafullaborade XML 2 May 22nd, 2008 06:21 AM
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
How to read file line by line in EVC++ iriskab Visual C++ 0 September 27th, 2006 01:39 PM
Reading line by line from a .txt file x_ray VB.NET 2002/2003 Basics 5 February 10th, 2006 01:55 PM
Line continuation character in ASP crmpicco Classic ASP Basics 3 June 20th, 2005 04:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.