[Home] [By Thread] [By Date] [Recent Entries]
doug@xxxxxxxxxxx wrote:
Can anyone point me towards XML/XSLT resources for generating Java source code? I'm looking for a simple working template that builds a basic .java file so that I can customize it to build more complex methods than the setter/getter methods that are generated by other frameworks I've been investigating.
Here is also a simplistic example (caution: badly designed XML): XML <?xml version="1.0" encoding="ISO-8859-1"?> <class name="stuff"> <attribute name="foo" type="int"/> </class> XSL <?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" encoding="ISO-8859-1"/> <xsl:template match="class">
<xsl:text>public class </xsl:text>
<xsl:value-of select="@name"/>
<xsl:text> {
</xsl:text>
<xsl:apply-templates select="attribute"/>
<xsl:text>}
</xsl:text>
</xsl:template> <xsl:template match="attribute">
<xsl:text> private </xsl:text>
<xsl:value-of select="@type"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@name"/>
<xsl:text> ;
</xsl:text>
<xsl:text> public </xsl:text>
<xsl:value-of select="@type"/>
<xsl:text> get</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text> () { return </xsl:text>
<xsl:value-of select="@name"/>
<xsl:text> ; }
</xsl:text>
</xsl:template>
</xsl:stylesheet>J.Pietschmann XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|

Cart



