Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
XML
problem with xalan indent from xml to html
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="hongping, post: 769494"] 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="[URL]http://www.w3.org/1999/XSL/Transform[/URL]" xmlns:xalan="[URL]http://xml.apache.org/xslt[/URL]" xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]"> <xsl:output method="xml" indent="yes" encoding="UTF-8" xalan:indent-amount="4" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]"/> <!-- *************************************************************** ** 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" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]"> <html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]"> <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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
XML
problem with xalan indent from xml to html
Top