夏兰+ XSLT+爪哇
我的 xsl 文件
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:good="xalan://com.epam.laba.model.Good"
xmlns:validator="xalan://com.epam.laba.validator.ValidatorXslGood">
<xsl:include href="parameter.xsl"/>
<xsl:param name="validator"/>
<xsl:param name="good"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/|node()|@*">
<xsl:if test="validator:validateGood($good)">
<xsl:copy>
<xsl:apply-templates
select="node()|@*" />
</xsl:copy>
</xsl:if>
</xsl:template>
......
Java 代码创建验证器并设置为 xsl
Good good=fillGood(parameters);
ValidatorXslGood validatorXslGood=new ValidatorXslGood();
Source sourceXSL = new StreamSource(xsltFile);
Transformer transformer = factory.newTransformer(sourceXSL);
transformer.setParameter(SUBCATEGORY_ID_VALUE, subcategoryId);
transformer.setParameter(GOOD, good);
transformer.setParameter(VALIDATOR, validatorXslGood);
transformer.transform(xmlSource, new StreamResult(outWriter));
但是
非静态 Java 函数“validateGood”的第一个参数不是有效的对象引用。 无法将数据类型“void”转换为“boolean”。
你能解释一下我出了什么问题吗?
UPD:
ValidatorXslGood.java 代码:
public class ValidatorXslGood {
private Good good;
private Map<String, String> setErrors;
private ResourceBundleManager errorManager;
public ValidatorXslGood() {
errorManager = new ResourceBundleManager();
errorManager.setResourceBundle(RESOURCE_BUNDLE__FOR_ERROR_FILE);
}
public Good getGood() {
return good;
}
public void setGood(Good good) {
this.good = good;
}
public boolean validateGood(Good good) {
if (checkingName(good.getName())) {
return true;
} else {
return false;
}
}
我尝试在 XSL 中创建验证器
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:good="xalan://com.epam.laba.model.Good"
xmlns:validator="xalan://com.epam.laba.validator.ValidatorXslGood"
extension-element-prefixes="validator" >
<xsl:include href="parameter.xsl"/>
<xsl:variable name="validatorConstructor" select="validator:new()"/>
<xsl:param name="validator"/>
<xsl:param name="good"/>
........
但是我有新的错误,我不明白路径中的错误在哪里
找不到类“com.epam.laba.validator.ValidatorXslGood”。不能 找到外部构造函数“com.epam.laba.validator.ValidatorXslGood”。
My xsl file
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:good="xalan://com.epam.laba.model.Good"
xmlns:validator="xalan://com.epam.laba.validator.ValidatorXslGood">
<xsl:include href="parameter.xsl"/>
<xsl:param name="validator"/>
<xsl:param name="good"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/|node()|@*">
<xsl:if test="validator:validateGood($good)">
<xsl:copy>
<xsl:apply-templates
select="node()|@*" />
</xsl:copy>
</xsl:if>
</xsl:template>
......
Java code where create validator and set to xsl
Good good=fillGood(parameters);
ValidatorXslGood validatorXslGood=new ValidatorXslGood();
Source sourceXSL = new StreamSource(xsltFile);
Transformer transformer = factory.newTransformer(sourceXSL);
transformer.setParameter(SUBCATEGORY_ID_VALUE, subcategoryId);
transformer.setParameter(GOOD, good);
transformer.setParameter(VALIDATOR, validatorXslGood);
transformer.transform(xmlSource, new StreamResult(outWriter));
but
The first argument to the non-static Java function 'validateGood' is not a valid object reference.
Cannot convert data-type 'void' to 'boolean'.
Can you explain me what wrong?
UPD:
ValidatorXslGood.java code:
public class ValidatorXslGood {
private Good good;
private Map<String, String> setErrors;
private ResourceBundleManager errorManager;
public ValidatorXslGood() {
errorManager = new ResourceBundleManager();
errorManager.setResourceBundle(RESOURCE_BUNDLE__FOR_ERROR_FILE);
}
public Good getGood() {
return good;
}
public void setGood(Good good) {
this.good = good;
}
public boolean validateGood(Good good) {
if (checkingName(good.getName())) {
return true;
} else {
return false;
}
}
I try create validator in XSL
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:good="xalan://com.epam.laba.model.Good"
xmlns:validator="xalan://com.epam.laba.validator.ValidatorXslGood"
extension-element-prefixes="validator" >
<xsl:include href="parameter.xsl"/>
<xsl:variable name="validatorConstructor" select="validator:new()"/>
<xsl:param name="validator"/>
<xsl:param name="good"/>
........
but i have new error and i can't understand where error in path
Cannot find class 'com.epam.laba.validator.ValidatorXslGood'. Cannot
find external constructor 'com.epam.laba.validator.ValidatorXslGood'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您错过了语法。 这里声明语法应该是prefix:methodName(object, args),其中 prefix 是扩展命名空间前缀(您需要将其声明为 xmlns:prefix="URI" extension-element-prefixes =“前缀..."),methodName 是使用 args 参数在 object 上调用的实例方法的名称。
It looks like you miss the syntax. Here it is stated that the syntax should be prefix:methodName(object, args), where prefix is the extension namespace prefix (which you need to declare as xmlns:prefix="URI" extension-element-prefixes="prefix ...") and methodName is the name of the instance method to invoke on object with the args arguments.