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
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
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
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