473,406 Members | 2,620 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,406 software developers and data experts.

Displaying XML document in ASP.NET page using XSL Transform

I have an XML document that I am trying to display in my ASP.NET page.

I am using an XSL Transform to display repeating XML data in a
specific format.

It reads the data, and displays it on my page, but there's a problem.

It runs all the data together on one line.

The XSL file is as follows:

-- begin xml ---

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/guestbook">
<xsl:apply-templates select="guestbook" />
<xsl:value-of select="name" />
<xsl:apply-templates select="guestbook" />
<xsl:value-of select="comment" />
</xsl:template>
</xsl:stylesheet>

-- end xml ---

I've tried putting <BR> in between the name and comment in the XSL
file and ASP.NET strips it out. I view the source in my browser and
for some reason ASP.NET just sends all the XML data as one string on
one line. I can't even figure out how to put spaces between the two
items.

I'd like to see:

Joe Blow

Hello, My Name is Joe.

Instead, what I get is:

Joe BlowHello, My Name is Joe.

Please help!!!
Nov 12 '05 #1
1 3713
First of all, that's all your XSLT will ever do irrespective of the XSLT
engine or framework.

You need to either generate HTML (the preferred method of output for XSLT
when trying to present data) or add the newline characters in yourself as
unicode character codes:

eg. newline is &#xA; [I think]

Try this example to see what should be happening (generates HTML):

XML:

<root>
<guestbook>
<entries>
<entry>
<name>Joe</name>
<comment>Nice place</comment>
</entry>
<entry>
<name>Jan</name>
<comment>Thanks for the lovely food</comment>
</entry>
<entry>
<name>Tim</name>
<comment>Thanks</comment>
</entry>
</entries>
</guestbook>
</root>

XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
<!-- Generate the root html node -->
<xsl:template match="/">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<!-- Match for the guestbook element -->
<xsl:template match="guestbook">
<h1>My Guestbook</h1>
<!-- Allow the default templates to process the remainder of the
document -->
<xsl:apply-templates/>
</xsl:template>
<!-- Match for the entry element -->
<xsl:template match="entry">
<h2>
<xsl:value-of select="name" />'s comment was:
</h2>
<p>
<xsl:value-of select="comment" />
</p>
<xsl:if test="not(position()=last())">
<hr/>
</xsl:if>
<!-- No need to apply further templates -->
</xsl:template>
</xsl:stylesheet>

Gives (XHTML):

<html>
<h1>My Guestbook</h1>
<h2>Joe's comment was:
</h2>
<p>Nice place</p>
<hr />
<h2>Jan's comment was:
</h2>
<p>Thanks for the lovely food</p>
<hr />
<h2>Tim's comment was:
</h2>
<p>Thanks</p>
</html>

Hope this helps.

Chris.

"Barry Anderberg" <ba******@yahoo.com> wrote in message
news:9d**************************@posting.google.c om...
I have an XML document that I am trying to display in my ASP.NET page.

I am using an XSL Transform to display repeating XML data in a
specific format.

It reads the data, and displays it on my page, but there's a problem.

It runs all the data together on one line.

The XSL file is as follows:

-- begin xml ---

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/guestbook">
<xsl:apply-templates select="guestbook" />
<xsl:value-of select="name" />
<xsl:apply-templates select="guestbook" />
<xsl:value-of select="comment" />
</xsl:template>
</xsl:stylesheet>

-- end xml ---

I've tried putting <BR> in between the name and comment in the XSL
file and ASP.NET strips it out. I view the source in my browser and
for some reason ASP.NET just sends all the XML data as one string on
one line. I can't even figure out how to put spaces between the two
items.

I'd like to see:

Joe Blow

Hello, My Name is Joe.

Instead, what I get is:

Joe BlowHello, My Name is Joe.

Please help!!!
Nov 12 '05 #2

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

Similar topics

1
by: Barry Anderberg | last post by:
I have an XML document that I am trying to display in my ASP.NET page. I am using an XSL Transform to display repeating XML data in a specific format. It reads the data, and displays it on my...
14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
0
by: Wynter | last post by:
RE: from Displaying a Document using the ASPNET user account to the Client Browser discussion (3/2/2004 Buddy Thanks for helping me on getting the document to display. But now I am left with a...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
by: Anthony Harkness-Gripe | last post by:
This is a very simple XSLT, and I'm doing it ways that I've had work before, but it's not displaying HTML. Is there a flaw in my logic? C#:...
7
by: DazedAndConfused | last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the left and right where there is no print. The document displays perfect in print preview, but when I print it, about 1/2 inch...
5
by: Lis | last post by:
Hi, I have inconsistent behavior of document() function which I hope someone can explain. I have Windows Service (runs as LocalSystem) that perform some Xslt transformation. In the stylesheet...
3
by: Rusty | last post by:
Hi, our intranet web site needs to add this feature. I've got the components but just need the last step to get it going. Here's the setup. 1) a user clicks on a link which calls a web service...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.