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>
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:
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.