這裡首先給一個xml例子,我們將通過一個xsl從該xml檔案中抽取有用的資訊來產生java代碼(實際上是一個javabean):
以下內容為程式碼
<?xml version="1.0" encoding="ISO-8859-1" ?>
<bean>
<name>Product</name>
<comments>This bean represents a product that the company
offers to its customers</comments>
<property>
<name>code</name>
<type>int</type>
<comments>the product inventory code</comments>
</property>
<property>
<name>name</name>
<type>String</type>
<comments>the product name</comments>
</property>
<property>
<name>testedOnAnimals</name>
<type>boolean</type>
<comments>the flag that indicates if the product was
tested on animals</comments>
</property>
<property>
<name>availableSince</name>
<type>java.util.Date</type>
<comments>the date when the company started offering this
product to its customers</comments>
</property>
</bean>
/**
* <xsl:value-of select="comments"/>//這裡是擷取xml文檔中的節點值
* This class has been generated by the XSLT processor from the
metadata
*/
public class <xsl:value-of select="name"/> {
/**
* Creates a new instance of the <xsl:value-of
select="name"/> bean
*/
public <xsl:value-of select="name"/>() {}
這裡列出結果:
以下內容為程式碼
/**
* This bean represents a product that the company offers to its
customers
* This class has been generated by the XSLT processor from the
metadata
*/
public class Product {
/**
* Creates a new instance of the Product bean
*/
public Product() {}
private int code;
/**
* Sets the product inventory code
* @param code is the product inventory code
*/
public void setCode(int code) {
this.code = code;
}
/**
* Returns the product inventory code
* @return the product inventory code
*/
public int getCode() {
return code;
}
private String name;
/**
* Sets the product name
* @param name is the product name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the product name
* @return the product name
*/
public String getName() {
return name;
}
private boolean testedOnAnimals;
/**
* Sets the flag that indicates if the product was tested on animals
* @param testedOnAnimals is the flag that indicates if the product
was tested on animals
*/
public void setTestedOnAnimals(boolean testedOnAnimals) {
this.testedOnAnimals = testedOnAnimals;
}
/**
* Returns the flag that indicates if the product was tested on
animals
* @return the flag that indicates if the product was tested on
animals
*/
public boolean isTestedOnAnimals() {
return testedOnAnimals;
}
private java.util.Date availableSince;
/**
* Sets the date when the company started offering this product to
its customers
* @param availableSince is the date when the company started
offering this product to its customers
*/
public void setAvailableSince(java.util.Date availableSince) {
this.availableSince = availableSince;
}
/**
* Returns the date when the company started offering this product
to its customers
* @return the date when the company started offering this product
to its customers
*/
public java.util.Date getAvailableSince() {
return availableSince;
}