473,763 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:xalan="ht tp://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 3044
I found out what is wrong. I need to use

<xsl:strip-space elements="pageD ata 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
6797
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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
0
2919
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 transformation. However, the transformation does not work. None of the templates in the XSLT source are Matched, except for the root template. The code is as follows:
1
1417
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 it's important :-) If I load my xml file in Netscape 7 it goes into the load loop and never comes out of it. I've been able to localize the problem. It's related to the document.write() JS call inside the template. If I would comment out the JS...
0
1262
by: Bloody Viking | last post by:
I'm using a variation on Donald Leslie's JAXPTransletMultipleTransformations.java (http://www.cs.helsinki.fi/group/xmltools/formatters/xalan/xalan-j_2_1_0/samples/translets/JAXPTransletMultipleTransformations.java), and it seems to work just fine. But then I copied it, the xml and the xslt over to another machine (both SPARC boxes) and got a strange result: character entities are getting translated strangely. For instance, &ecirc; is...
1
1669
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 matches nodes looks like this: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
3229
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 that I could externalize my JavaScript, but that will not be practical throughout this application. Is there any way to get around this issue? Xalan processor. Stripped down stylesheet below along with XHTML output. <?xml version='1.0'?>...
2
1514
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 id="green>55</entry> <entry id="blue">123</entry> so I could acces them with something like $returned. Problem is, I haven't figured out how to do that. I haven't found any
5
1296
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 when serliaze xml with java, you can place a parameter saying the xml string will be output in human readble form.
0
1161
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 file to set these ones. When my ejb uses these xalan classes (... or i think it uses) i recived a messagge like this: 15:10:31,414 ERROR ERROR: 'org/apache/xml/utils/ObjectFactory' 15:10:31,414 ERROR FATAL ERROR: 'Could not compile...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9998
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.