如何检测丢失的文件而不抛出错误

问题描述 投票:0回答:1

我提到了xsl中的xml文件路径,但我想暂时删除文件夹中的那个xml文件,并且我总是想保留在xsl中。但是当我删除它时显示警告。

<xsl:apply-templates mode="replaceVariables"
            select="document('../Folder_1/Test.xml')">
</xsl:apply-templates>

我从

Test.xml
中删除了
Folder_1
。当我运行时,出现以下错误

Engine name: Saxon-PE 9.9.1.7
Severity: warning
Description: I/O error reported by XML parser processing file:/C:/Work/Folder_1/Test.xml: C:/Work/Folder_1/Test.xml (The system cannot find the file specified)
Start location: 674:48
Length: 1

即使 xml 文件在相应的提到的文件夹中删除,它在转换时也不应该显示错误。

xml xslt xslt-2.0
1个回答
0
投票

在 XSLT 2.0 及更高版本中,有 XPath 2.0 及更高版本的函数

doc-available
例如
doc-available('../Folder_1/Test.xml')
,因此您可以在
xsl:if
周围使用
xsl:apply-templates
检查,或者您甚至可以在
select
表达式的谓词中使用该检查。

© www.soinside.com 2019 - 2024. All rights reserved.