Displaying XML document in ASP.NET page using XSL Transform

Discussion in 'ASP .Net' started by Barry Anderberg, Apr 8, 2004.

  1. 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!!!
    Barry Anderberg, Apr 8, 2004
    #1
    1. Advertising

  2. Barry Anderberg

    Dan Brussee Guest

    The XSL transform document requires exact XML formatting. Your <BR>
    will need to change to <BR/>. Other than that, I would think that
    would work. As for the space, you need to use the XSL variant of a
    space. Somthing like #160; or something like that. (been a while for
    xsl for me)

    On 7 Apr 2004 19:20:58 -0700, (Barry Anderberg)
    wrote:

    >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!!!
    Dan Brussee, Apr 8, 2004
    #2
    1. Advertising

  3. Barry Anderberg

    Chris Barber Guest

    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
    [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:eek:utput 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" <> wrote in message
    news:...
    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!!!
    Chris Barber, Apr 8, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    0
    Views:
    996
    KathyB
    Jun 25, 2003
  2. Anthony Harkness-Gripe

    Dataset to XSL Transform not displaying HTML--only XML

    Anthony Harkness-Gripe, Aug 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    976
    itnrant
    Jul 8, 2008
  3. Greg Collins [MVP]
    Replies:
    5
    Views:
    5,579
    Anton Lapounov [MSFT]
    Aug 31, 2004
  4. telescient telescient via .NET 247

    How to transform xml variable to xsl file using asp.net using vb.net

    telescient telescient via .NET 247, Apr 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    834
    Matt Berther
    Apr 4, 2005
  5. Barry Anderberg
    Replies:
    1
    Views:
    1,206
    Chris Barber
    Apr 8, 2004
Loading...

Share This Page