Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I detect a missing file and not throw an error

I mentioned the xml file path in the xsl, but I want to delete that xml file in the folder for now and I always want to keep in the xsl. But when I’m removing it showing the warning.

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

I deleted the Test.xml from the Folder_1. When I’m running I’m getting the below error

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

Even though the xml file delete in the corresponding mentioned folder it shouldn’t show error while converting.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In XSLT 2.0 and later there is the XPath 2.0 and later function doc-available e.g. doc-available('../Folder_1/Test.xml') so you can use an xsl:if check around your xsl:apply-templates or you might even be able to use the check in a predicate of the select expression.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading