开发者

Xalan+ XSLT+ JAVA

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开发者_StackOverflow中文版: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'.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜