我想检查XSLT是否存在HTML文件.我怎样才能做到这一点?我已经从这里https://gist.github.com/emth/4531924尝试了file-exist.xsl,但它对我不起作用.我一直试图让它运行超过2个小时,但我被卡住了.这是我的蚂蚁片段:
<target name="transform">
<xslt in="/tmp/sample.xml" out="/tmp/out.html" style="/tmp/sample.xsl" />
</target>
Run Code Online (Sandbox Code Playgroud)
这是我的xslt文件:
<?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>
....
Run Code Online (Sandbox Code Playgroud)
用ant运行它会得到以下错误:
[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
Run Code Online (Sandbox Code Playgroud)
任何人都可以为我提供一个运行示例,还是有其他替代方案?谢谢!
我找到了一个解决方案:
<xsl:when test="fs:exists(fs:new('myfile.html'))" xmlns:fs="java.io.File">
<!-- do something here... -->
</xsl:when>
Run Code Online (Sandbox Code Playgroud)
它独立于XSLT 1.0或2.0