Test whether file exists
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 71
- Joined: Sat Jan 07, 2017 1:23 am
Test whether file exists
I'm creating a transformation during which I need to know whether a file exists. I found this solution online:
but after adding this to my stylesheet, the test always fails, but I'm not seeing any error message. (The named file is in the same directory as the stylesheet itself.)
My transformation is running with Saxon-PE 9.6.0.7.
Where do I start to troubleshoot this?
Code: Select all
<xsl:choose>
<xsl:when test="fs:exists(fs:new('AJS405045.xml'))" xmlns:fs="java.io.File">
<xsl:message><xsl:text>Found it!</xsl:text></xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:message><xsl:text>Missing!</xsl:text></xsl:message>
</xsl:otherwise>
</xsl:choose>
My transformation is running with Saxon-PE 9.6.0.7.
Where do I start to troubleshoot this?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Test whether file exists
Hi,
If you're running this on Linux (also applies to some OS X file systems), the file names are case sensitive, so check the exact file name (uppercase/lowercase letters).
I would also recommend testing with an absolute file path. So, instead of 'AJS405045.xml' use '/path/to/my/file/AJS405045.xml'.
Regards,
Adrian
So, the transformation is successful but it always goes the xsl:otherwise route. Is that correct?the test always fails
If you're running this on Linux (also applies to some OS X file systems), the file names are case sensitive, so check the exact file name (uppercase/lowercase letters).
I would also recommend testing with an absolute file path. So, instead of 'AJS405045.xml' use '/path/to/my/file/AJS405045.xml'.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 71
- Joined: Sat Jan 07, 2017 1:23 am
Re: Test whether file exists
Sorry for the late reply--I neglected to check "Notify me when a reply is posted".
Thanks, Adrian: specifying the absolute file path solved the problem.
FWIW, I'm running this in Oxygen 18.1 on OS X 10.11.6 (El Capitan), so I'm accustomed to assuming filenames are case-sensitive.
Using the absolute path works with both of the following tests:
and
Thanks, Adrian: specifying the absolute file path solved the problem.
FWIW, I'm running this in Oxygen 18.1 on OS X 10.11.6 (El Capitan), so I'm accustomed to assuming filenames are case-sensitive.
Using the absolute path works with both of the following tests:
Code: Select all
<xsl:when test="file:exists('mrb.txt')" xmlns:file="http://expath.org/ns/file">
Code: Select all
<xsl:when test="fs:exists(fs:new('mrb.txt'))" xmlns:fs="java.io.File">
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service