467,925 Members | 1,780 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,925 developers. It's quick & easy.

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
  • viewed: 3460
Share:
1 Reply
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

136 posts views Thread by Matt Kruse | last post: by
reply views Thread by Anthony Harkness-Gripe | last post: by
7 posts views Thread by DazedAndConfused | last post: by
5 posts views Thread by Lis | last post: by
3 posts views Thread by Rusty | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.