我有一个XML 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
这个XSL 文件:
<?xml version="1.0" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="/catalog/cd/artist"/>
<xsl:variable name = "artist" select = "/catalog/cd/artist()"/>
<xsl:variable name="year" select="/catalog/cd/year()"/>
<xsl:Object-bean name="{$artist}" id="{$year}">
</xsl:Object-bean>
</xsl:template>
</xsl:stylesheet>
现在我想将结果转换为 Java 类。
爪哇:
@XmlRootElement(name = "Object-bean")
@XmlAccessorType(XmlAccessType.NONE)
public class ObjectBean {
@XmlAttribute(name = "name")
private String name;
@XmlAttribute
private String id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
但是当我运行它时,它向我显示了这个错误:
Error at xsl:Object-bean on line 7 column 49 of test.xsl:
XTSE0010: Unknown XSLT element: Object-bean
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.
at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:176)
at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139)
at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:91)
at XslExecutor.main(XslExecutor.java:28)