Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if xml file exists with XSLT 2.0, saxon9HE

Tags:

xml

xslt

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.

like image 458
user3629892 Avatar asked Jun 01 '15 15:06

user3629892


1 Answers

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>
like image 100
davidcondrey Avatar answered Nov 01 '22 18:11

davidcondrey