我如何能为您在XSLT文件是否存在?

问题描述:

我想在XSLT来检查HTML文件是否存在。
我怎样才能做到这一点?
我已经从这里 https://gist.github.com/emth/4531924试过文件exists.xsl 但它不为我工作。我一直在试图得到它运行2个多小时了,但我坚持。
这里是我的蚂蚁片断:

I would like to check in XSLT whether an HTML file exists or not. How can I do this? I have already tried the file-exists.xsl from here https://gist.github.com/emth/4531924 but it doesn't work for me. I've been trying to get it running for over 2 hours now, but I am stuck. Here's my ant snippet:

<target name="transform">
    <xslt in="/tmp/sample.xml" out="/tmp/out.html" style="/tmp/sample.xsl" />
</target>

这是我的XSLT文件:

and this is my xslt file:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:java="http://www.java.com/">
<xsl:import href="file-exists.xsl"/>
...    
<xsl:if test="java:file-exists('myfile.html', base-uri())">
    <!-- do something here... -->
</xsl:if>
....

与蚂蚁运行这一点,我会收到以下错误:

Running this with ant I will get the following error:

[xslt] Processing /tmp/sample.xml to /tmp/out.html
[xslt] Loading stylesheet /tmp/sample.xsl
[xslt] : Error! The first argument to the non-static Java function 'fileExists' is not a valid object reference.
[xslt] : Error! Cannot convert data-type 'void' to 'boolean'.
[xslt] : Fatal Error! Could not compile stylesheet
[xslt] Failed to process /tmp/sample.xml

有人能为我提供一个运行的例子或有任何其他的选择吗?谢谢!

Can anybody provide me a running example or is there any other alternative? Thanks!

我已经找到了解决办法:

I've found a solution:

<xsl:when test="fs:exists(fs:new('myfile.html'))" xmlns:fs="java.io.File">
    <!-- do something here... -->
</xsl:when>

和它独立运行XSLT 1.0或2.0的

and it works independently of XSLT 1.0 or 2.0