problem with xalan indent from xml to html

Discussion in 'XML' started by hongping, Oct 27, 2003.

  1. hongping

    hongping Guest

    I am having problems transforming a xml doc into html with proper
    indenting.

    Here is the xslt
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xslt"
    xmlns="http://www.w3.org/1999/xhtml">

    <xsl:eek:utput method="xml" indent="yes" encoding="UTF-8"
    xalan:indent-amount="4"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
    <!--

    ***************************************************************
    ** Top level template. Creates the framework for the XHTML page
    ************************************************************-->
    <xsl:template match="/">
    <html>
    <head>
    <title>XSLT page generation</title>
    </head>
    <body>
    <xsl:apply-templates select="/pageData"/>
    </body>
    </html>
    </xsl:template>
    <!--

    ***************************************************************
    ** pageData element
    ************************************************************-->
    <xsl:template match="pageData">
    <h3>Your Page...</h3>

    <table border="0" cellpadding="2" cellspacing="0">
    <xsl:apply-templates/>
    </table>

    </xsl:template>
    <!--

    ***************************************************************
    ** Output a section
    ************************************************************-->
    <xsl:template
    match="section">
    <tr>
    <td>
    <span id="{@name}">
    <b><xsl:value-of select="@name"/></b>
    </span>
    </td>
    <td>
    <xsl:value-of select="."/>
    </td>
    </tr>
    </xsl:template>
    </xsl:stylesheet>


    Here is the sample input:
    <pageData>
    <section name="first section">This is first section!!</section>
    <section name="second section">This is the second
    section!</section></pageData>


    Here is the output, which is not indented properly
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>XSLT page generation</title>
    </head>
    <body>
    <h3>Your Page...</h3>
    <table cellspacing="0" cellpadding="2" border="0">
    <tr>
    <td>
    <span id="first section">
    <b>first section</b>
    </span>
    </td>
    <td>This is first section!!</td>
    </tr>
    <tr>
    <td>
    <span id="second section">
    <b>second section</b>
    </span>
    </td>
    <td>This is the second section!</td>
    </tr>
    </table>
    </body>
    </html>

    The <tr> at the beginning of each section is not indented for some
    reasons.
    I also noticed that if my input contains extra spaces or line breaks
    outside the <section>, they will affect the formatting as well.

    I would appreciate any help.

    Thanks,
    Hongping
    hongping, Oct 27, 2003
    #1
    1. Advertising

  2. hongping

    hongping Guest

    I found out what is wrong. I need to use

    <xsl:strip-space elements="pageData section" />

    to specify the elements that should be stripped of extra whitespaces.
    hongping, Nov 2, 2003
    #2
    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. bastien

    XSL+XML=> HTML using xalan.

    bastien, May 25, 2004, in forum: XML
    Replies:
    0
    Views:
    479
    bastien
    May 25, 2004
  2. cvissy
    Replies:
    0
    Views:
    600
    cvissy
    Nov 16, 2004
  3. @cl

    Xml indent problem

    @cl, Sep 13, 2006, in forum: XML
    Replies:
    2
    Views:
    693
  4. dt
    Replies:
    4
    Views:
    469
    CBFalconer
    Dec 31, 2006
  5. Xh
    Replies:
    7
    Views:
    1,049
    Joseph Kesselman
    Mar 19, 2007
Loading...

Share This Page