[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Code Generation

Subject: Re: Code Generation
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Wed, 01 May 2002 00:32:40 +0200
Re:  Code Generation
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.

Cocoon generates Java source from XSP files using XSLT. The most important point is to use the text output method and perhaps an output encoding the Java compiler doesn't choke on. Further issues are whether you want to have a human redable output, beautifully indented (you have to do it yourself, indent="yes" doesn't work here), and how you want to relate problems reported by the compiler or during run time (stack traces) to your source XML or the boilerplate code in your style sheet. Saxon has a lineNumber() extension function, which can help here (put the source line number in a comment).

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> {&#x0A;</xsl:text>
    <xsl:apply-templates select="attribute"/>
    <xsl:text>}&#x0A;</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> ;&#x0A;</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> ; }&#x0A;</xsl:text>
  </xsl:template>
</xsl:stylesheet>

J.Pietschmann


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread
  • Re: Code Generation
    • doug - Tue, 30 Apr 2002 16:48:17 -0400 (EDT)
      • J.Pietschmann - Tue, 30 Apr 2002 18:26:05 -0400 (EDT) <=
      • Sal Mangano - Tue, 30 Apr 2002 18:42:43 -0400 (EDT)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.