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">
<xslutput 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
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">
<xslutput 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