473,792 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with xsl:for-each whitespace

f
I am writing a java code generation tool. I use xml and xslt. But I
have some problem using xsl:for-each.

here is my xml
<?xml version = "1.0"?>
<CLASS
package_name=". test"
name="TestAnaly sis"
scope="public">
<ATTR name="tof" type="double" scope="public"/>
<ATTR name="svd" type="double" scope="public"/>
<ATTR name="ttt" type="double" scope="public"/>
<METHOD name="getTof" type="double" scope="public">
<CODE>return tot;</CODE>
</METHOD>
</CLASS>

here is my xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>

<xsl:template match="CLASS">

import <xsl:value-of select="./@package_name"/>;

/** This file is generated by
*/
<xsl:value-of select="./@scope"/> class <xsl:value-of
select="./@name"/>
{
<xsl:for-each select="ATTR">
<xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
<xsl:value-of select="./@name"/>;
</xsl:for-each>

<xsl:for-each select="METHOD" >
<xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
<xsl:value-of select="./@name"/>{
<xsl:value-of select="CODE"/>;
}
</xsl:for-each>
};
</xsl:template>

</xsl:stylesheet>

But here is my output:

import test;

/** This file is generated by

*/

public class TestAnalysis

{

publicdoubletof ;

publicdoublesvd ;

publicdoublettt ;

publicdoubleget Tof{

return tot;;

}

};

I miss all the whitespace. How can I fix it?

Thanks,

ff
Jul 20 '05 #1
2 2021
Replace:
<xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
<xsl:value-of select="./@name"/>;
with

<xsl:value-of select="concat( @scope, ' ', @type, ' ', @name, ';')"/>

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


"f" <ff****@yahoo.c om> wrote in message
news:8f******** *************** ***@posting.goo gle.com... I am writing a java code generation tool. I use xml and xslt. But I
have some problem using xsl:for-each.

here is my xml
<?xml version = "1.0"?>
<CLASS
package_name=". test"
name="TestAnaly sis"
scope="public">
<ATTR name="tof" type="double" scope="public"/>
<ATTR name="svd" type="double" scope="public"/>
<ATTR name="ttt" type="double" scope="public"/>
<METHOD name="getTof" type="double" scope="public">
<CODE>return tot;</CODE>
</METHOD>
</CLASS>

here is my xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>

<xsl:template match="CLASS">

import <xsl:value-of select="./@package_name"/>;

/** This file is generated by
*/
<xsl:value-of select="./@scope"/> class <xsl:value-of
select="./@name"/>
{
<xsl:for-each select="ATTR">
<xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
<xsl:value-of select="./@name"/>;
</xsl:for-each>

<xsl:for-each select="METHOD" >
<xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
<xsl:value-of select="./@name"/>{
<xsl:value-of select="CODE"/>;
}
</xsl:for-each>
};
</xsl:template>

</xsl:stylesheet>

But here is my output:

import test;

/** This file is generated by

*/

public class TestAnalysis

{

publicdoubletof ;

publicdoublesvd ;

publicdoublettt ;

publicdoubleget Tof{

return tot;;

}

};

I miss all the whitespace. How can I fix it?

Thanks,

ff

Jul 20 '05 #2
>>>>> "Dimitre" == Dimitre Novatchev <dn********@yah oo.com> writes:

Dimitre> Replace:
<xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
<xsl:value-of select="./@name"/>;


Dimitre> with

Dimitre> <xsl:value-of select="concat( @scope, ' ', @type, ' ', @name,
Dimitre> ';')"/>

Yes, I also use xsl to generate java, and use concat alot. I have a couple
of variables I use lot: indent1, indent2, .. where indent1 is four spaces,
indent2 eight spaces etc. Then I have variables newline and quote. So almost
all lines are of form

<xsl:value-of select="concat( $indent2,'Syste m.out.println(' ,
$quote,'Value is ',$quote,'+',@n ame,');',
$newline)"/>

--
Arto V. Viitanen av@cs.uta.fi
University of Tampere, Department of Computer Sciences
Tampere, Finland http://www.cs.uta.fi/~av/
Jul 20 '05 #3

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

Similar topics

1
3287
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag using the name attribute "src" won't make the correct link to the gif file. why? <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
0
1081
by: Wilson Wu | last post by:
Hi, How can i create a xml and xsl for more than one worksheet. Thanks Wilson
0
1067
by: Daniel Roth | last post by:
Solution to the Back button problem for IE 5.5 and above. 1) Get rid of the cache Response.CacheControl = "no-cache"; Response.AddHeader("Pragma", "no-cache"); 2) set SmartNavigation = true Daniel Roth
2
1200
by: zawpai | last post by:
Hello, I have a problem for creating the exe file. I can create it, but it shows "Run time error '76' " and "path not found". I don't know how I can solve that problem. Could anyone please show me the way to solve it? Thanks. zawpai
0
1006
by: sa6113 | last post by:
I am using this code to connect to a windows machine using paramiko, I have installed sshd on the machine and it works properly: sock.connect((hostname, port)) t = paramiko.Transport(sock) event = threading.Event() t.start_client(event) event.wait() if not t.is_active(): print 'SSH negotiation failed.'
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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
10211
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
7538
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
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
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

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.