problem with xalan indent from xml to html

hongping

Usenet Archive
Joined
Oct 27, 2003
Messages
2
Reaction score
0
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

Usenet Archive
Joined
Oct 27, 2003
Messages
2
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top