Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 为什么会出现以下异常';非静态Java函数的第一个参数';?_Xslt_Xml Parsing_Xslt 2.0 - Fatal编程技术网

Xslt 为什么会出现以下异常';非静态Java函数的第一个参数';?

Xslt 为什么会出现以下异常';非静态Java函数的第一个参数';?,xslt,xml-parsing,xslt-2.0,Xslt,Xml Parsing,Xslt 2.0,我得到一个例外: 致命错误:“非静态Java函数***的第一个参数不是有效的对象引用。” 当我尝试使用XMLMaven插件转换XML文档时,就会发生这种情况 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xml-maven-plugin</artifactId> <version>1.0</version> &l

我得到一个例外:

致命错误:“非静态Java函数***的第一个参数不是有效的对象引用。”

当我尝试使用XMLMaven插件转换XML文档时,就会发生这种情况

<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>
XSL转换文件的内容

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

我在尝试使用XSLT 2.0“样式表”进行转换时遇到此错误,但我使用的是XSLT 1.0解析器

在我的例子中,当我删除saxon的maven依赖项时就会发生这种情况,saxon是XSLT2.0解析器。 Java7附带的XSLT解析器只能处理XSLT1.0

Maven的解决方案是保留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>

org.codehaus.mojo
xml maven插件
1
准备包装
使改变
net.sf.saxon.TransformerFactoryImpl
src/main/resources/xml
src/main/resources/xslt/my-transformation.xsl
**/*.xml
目标/生成/wsdl
net.sf.saxon
萨克森河
9.6.0-5

任何标准都没有定义处理从XSLT到Java的调用,这完全取决于您使用的XSLT处理器


另外请注意,如果您使用的是Saxon,那么8.7版非常旧(大约2006年)。当前版本是9.6。

对我来说,忘记将调用的java类添加到类路径只是一个愚蠢的错误。在eclipse中,您可以在运行-->运行配置…-->类路径选项卡并添加正确的java类。

“我得到这个异常”不是问题。我还建议将标题中的错误信息拉下来,并将其放在正文中。我正确地阐述了问题,并演示了整个案例。因为这个问题引起了你的兴趣,所以说一个肯定的观点是公平的。我将取消我的推论,因为“我有这个问题”是一个有效的问题,即使没有问号。但我很难理解这个问题。可能是我糊涂了。但是在正文中重述您的问题可能会帮助那些容易分心的人。正如我在回答中所说的,如果您切换到不同的XSLT处理器,您可以期望对外部Java函数的调用以完全不同的方式工作。我知道,但根据处理器显示的异常情况,根本不清楚。同意,当我使用saxon处理器时,它是工作的。这就是这个问题/答案所展示的。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>