gpt4 book ai didi

java - Xalan+ XSLT+ Java

转载 作者:行者123 更新时间:2023-11-30 07:31:19 27 4
gpt4 key购买 nike

我的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>

……

创建 validator 并设置为 xsl 的 Java 代码

    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));

但是

The first argument to the non-static Java function 'validateGood' is not a valid object reference. Cannot convert data-type 'void' to 'boolean'.

你能解释一下哪里错了吗?

更新:

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 中创建 validator

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"/>

........

但是我有新的错误,我无法理解路径中的错误

Cannot find class 'com.epam.laba.validator.ValidatorXslGood'. Cannot find external constructor 'com.epam.laba.validator.ValidatorXslGood'.

最佳答案

看起来你错过了语法。 Here声明语法应为prefix:methodName(object, args),其中prefix 是扩展命名空间前缀(您需要将其声明为xmlns: prefix="URI"extension-element-prefixes="prefix ...") 和 methodName 是在object 上调用的实例方法的名称args 参数。

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:validator="xalan://com.epam.laba.parser.validator.ValidatorXslGood"
extension-element-prefixes="validator" ... >

<xsl:param name="validator"/> <!-- That is in reality validatorObject -->
<xsl:param name="good"/>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/|node()|@*">
<xsl:if test="validator:validateGood($validator, $good)">
...

关于java - Xalan+ XSLT+ Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7400510/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com