473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem with xalan indent from xml to html

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:output 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
Jul 20 '05 #1
1 3015
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.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
0
by: Dominique Bejean | last post by:
Hello, I am having a problem doing an XSLT transformation using Java. I have a XML document as a DOM Document object, wrap the Document object with a DOMSource object, and do the...
1
by: Pavel | last post by:
Greetings to all - I've noticed that my xsl transformation does not work in Netscape 7. It worked fine in Netscape 6.1, or if html file is generated using xalan (and it works in IE 5, not that...
0
by: Bloody Viking | last post by:
I'm using a variation on Donald Leslie's JAXPTransletMultipleTransformations.java...
1
by: pgreaves | last post by:
hi there i have developed a style sheet that works fine in the XML perspective of Rational Software architect, but when i add it to my application, it appears to match no nodes. my XSL that...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
2
by: henribastien | last post by:
I'm trying to return an array from a xalan extension but so far I have made no progress. What I would like to return is something like that <entry id="red">201</entry> <entry...
5
by: Elhanan | last post by:
hi.. i don't exactly how to calls this , but is there a property for xalan, to output xml with crarriage return? i'm trying out xslt and the output can't be read with a normal editor, i know...
0
by: ramonio | last post by:
Hello, i am using jboss 4 and my application needs to use some xalan.jar and xerces.jar older than the ones uses jboss. (at lib/endorsed/) I use the application.xml from the ear file application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.