Why do I get the following exception 'first ar

2019-09-05 07:53发布

I get this exception:

FATAL ERROR: 'The first argument to the non-static Java function *** is not a valid object reference.'

This happens when I try to transform an XML document using the xml-maven-plugin.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <goals>
                <goal>transform</goal>
           </goals>
        </execution>
    </executions>
    <configuration>
        <transformationSets>
            <transformationSet>
                <dir>target/generated/wsdl</dir>
                <stylesheet>src/test/resources/transform/my-transformation.xsl</stylesheet> 
                <includes>   
                    <include>**/*.xsd</include>
                </includes>
                <outputDir>target/generated/wsdl</outputDir>
            </transformationSet>
         </transformationSets>
    </configuration>
</plugin>

Error message

 [INFO] --- xml-maven-plugin:1.0:transform (transform--xsd) @ my-pom ---
 Warning:  org.apache.xerces.parsers.SAXParser: Feature 'http://javax.xml.XMLConstants/feature/secure-processing' is not recognized.
 Warning:  org.apache.xerces.parsers.SAXParser: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
 Warning:  org.apache.xerces.parsers.SAXParser: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
 ERROR:  'The first argument to the non-static Java function 'isTheRightElement' is not a valid object reference.'
 FATAL ERROR:  'The first argument to the non-static Java function 'isTheRightElement' is not a valid object reference.'

XSL Transformation file's content

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://mysite/mycreate" xmlns:xalan="http://xml.apache.org/xslt" xmlns:mytag="http://andreas/ps-transformations" version="2.0">
<xsl:strip-space elements="*"/> 
<xsl:output method="xml" indent="yes" xalan:indent-amount="4"/>

<xsl:variable name="myAnnotations" select="document('element-list.xml')"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="xs:element">     
    <xsl:param name="myValue" select="normalize-space(mytag:isTheRightElement(@class))"/>

    <xsl:choose>
        <xsl:when test="$myValue=''">
            <xsl:copy> 
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:when>
        <xsl:otherwise>
             <xsl:copy> 
                <xsl:apply-templates select="@*|node()"/>
                <xsl:element name="xs:annotation"> 
                    <xsl:element name="xs:documentation">
                        <xsl:value-of select="$elementValue"/>
                    </xsl:element>
                </xsl:element> 
            </xsl:copy>
        </xsl:otherwise>
      </xsl:choose>
</xsl:template> 

<xsl:function name="myTag:isTheRightElement">
    <xsl:param name="class"/>  
       <xsl:for-each select="$myAnnotations/elementList/element">
            <xsl:if test="lower-case(@class) = 'something'">
               <xsl:value-of select="text()"/>           
            </xsl:if>
         </xsl:for-each> 
    </xsl:function>    
</xsl:stylesheet>

2条回答
相关推荐>>
2楼-- · 2019-09-05 08:03

I get this error when trying to transform using an XSLT 2.0 'stylesheet', but I use an XSLT 1.0 parser.

In my case, this happens when I remove the maven dependency of saxon, which is an XSLT 2.0 parser. The XSLT parser that comes with Java 7 can handle only XSLT 1.0.

Maven solution is to keep the Saxon:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xml-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>transform</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <transformerFactory>net.sf.saxon.TransformerFactoryImpl</transformerFactory>
        <transformationSets>
            <transformationSet>
                <dir>src/main/resources/xml</dir>
                <stylesheet>src/main/resources/xslt/my-transformation.xsl</stylesheet>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <outputDir>target/generated/wsdl</outputDir>
            </transformationSet>
        </transformationSets>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>Saxon-HE</artifactId>
            <version>9.6.0-5</version>
        </dependency>
    </dependencies>
</plugin>
查看更多
倾城 Initia
3楼-- · 2019-09-05 08:28

Handling of calls from XSLT to Java is not defined in any standard - it depends entirely on which XSLT processor you are using.

Note also, if you're using Saxon, version 8.7 is VERY old (about 2006). The current version is 9.6.

查看更多
登录 后发表回答