473,386 Members | 1,647 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,386 software developers and data experts.

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="TestAnalysis"
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:stylesheet 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;

publicdoublegetTof{

return tot;;

}

};

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

Thanks,

ff
Jul 20 '05 #1
2 2000
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.com> wrote in message
news:8f**************************@posting.google.c om... 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="TestAnalysis"
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:stylesheet 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;

publicdoublegetTof{

return tot;;

}

};

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

Thanks,

ff

Jul 20 '05 #2
>>>>> "Dimitre" == Dimitre Novatchev <dn********@yahoo.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,'System.out.println(',
$quote,'Value is ',$quote,'+',@name,');',
$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
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...
0
by: Wilson Wu | last post by:
Hi, How can i create a xml and xsl for more than one worksheet. Thanks Wilson
0
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...
2
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...
0
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)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.