problem with xsl:for-each whitespace

F

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:eek:utput 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
 
A

Arto V. Viitanen

Dimitre> Replace:
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)"/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top