夏兰+ XSLT+爪哇

发布于 2024-12-04 16:53:48 字数 2650 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鼻尖触碰 2024-12-11 16:53:48

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

<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)">
...

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.

<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)">
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文