user3629892
user3629892

Reputation: 3046

check if xml file exists with XSLT 2.0, saxon9HE

I'd like to check, whether a file exists, with xslt 2.0. However, it's not working. I've tried this:

<xsl:choose>
    <xsl:when test="doc(iri-to-uri(concat($currFolder, '/', $currSubFolder, '/', @href)))">

(The path is correct)

however, this results in an error, when the file isnt there.

and this:

<xsl:choose>
    <xsl:when test="doc-available(iri-to-uri(concat($currFolder, '/', $currSubFolder, '/', @href)))">

doesn't work, it tells me files are there that clearly don't exist.

Whats the correct way to do this? A reliable way to check, if an xml file exists.

Upvotes: 7

Views: 1780

Answers (1)

davidcondrey
davidcondrey

Reputation: 35953

According to this similar question, the author mentions that something such as this worked for them as far as checking for the existence of an xml file.

Right now, it checks each folder individually an if the file doesnt exist in that folder, it writes it to the output, regardless of whether it already exists in another previous folder.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:variable name="currInput" select="tokenize(document-uri(.), '/')[last()]"/>
    <xsl:choose>
        <xsl:when test="doc-available(iri-to-uri(concat(.,'/',$currInput))) = fn:false()"></xsl:when>

Upvotes: 3

Related Questions