[oXygen-user] Checking whether a file exists in XSLT

Dr. Patrik Stellmann Patrik.Stellmann at gdv-dl.de
Fri Jan 13 01:49:01 CST 2017


I just tested you code (also with oXygen 18.1 but with minimal modifications on a dita map) and it worked fine:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">

<xsl:mode name="#default" on-no-match="shallow-skip"/>

<xsl:template match="topicref">
<xsl:variable name="filename" as="xs:string">
<xsl:value-of select="@href"/>
</xsl:variable>
<xsl:variable name="resolvedFile" as="xs:anyURI"
select="resolve-uri(@href, base-uri(.))"/>
<xsl:message>
<xsl:value-of select="concat($filename, ' resolves to ', $resolvedFile)"/>
</xsl:message>

<xsl:if test="not(fs:exists(fs:new($resolvedFile)))"
xmlns:fs="java.io.File">
<xsl:value-of select="concat($filename, '   Not Found')"/>
</xsl:if>
<xsl:text>
         </xsl:text>

</xsl:template>

</xsl:stylesheet>

I'd recommend you to create a similar minimal sample to make sure the problem lies really within this piece of code.

Patrik


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel: +49 40 33449-1142
Fax: +49 40 33449-1400
E-Mail: mailto:Patrik.Stellmann at gdv-dl.de

-----Ursprüngliche Nachricht-----
Von: oXygen-user [mailto:oxygen-user-bounces at oxygenxml.com] Im Auftrag von Lou Burnard
Gesendet: Donnerstag, 12. Januar 2017 19:59
An: oxygen-user at oxygenxml.com
Betreff: [oXygen-user] Checking whether a file exists in XSLT

I need to write a stylesheet which checks the value of an attribute to see if it is the name of an existing file. You can't do it directly in XSLT of course, so I am following the advice of Mike Kay
(https://www.oxygenxml.com/archives/xsl-list/200506/msg00400.html) and trying to do it with a java extension in an XSLT2 stylesheet. Here's the relevant template, which I run with saxon EE within oXygen 18.1

<xsl:template match="tei:pb">
         <xsl:variable name="filename" as="xs:string">
             <xsl:value-of select="@facs"/>
         </xsl:variable>
         <xsl:variable name="resolvedFile" as="xs:anyURI"
            select="resolve-uri(@facs, base-uri(.))"/>
         <xsl:message>
             <xsl:value-of select="concat($filename, ' resolves to ', $resolvedFile)"/>
         </xsl:message>

         <xsl:if test="not(fs:exists(fs:new($resolvedFile)))"
             xmlns:fs="java.io.File">
             <xsl:value-of select="concat($filename, '   Not Found')"/>
         </xsl:if>
         <xsl:text>
         </xsl:text>

     </xsl:template>

The messages produced tell me that the filenames are being resolved correctly (they are all relative URLs like this
../../something/foo/foo.jpg) but the test always returns true, whether the file concerned exists or not. Am I missing something obvious? Or not obvious? This has been driving me nuts all day...



_______________________________________________
oXygen-user mailing list
oXygen-user at oxygenxml.com
https://www.oxygenxml.com/mailman/listinfo/oxygen-user

GDV Dienstleistungs-GmbH & Co. KG
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRA 93 894
USt.-IdNr : DE 205183123

Komplementärin: 
GDV Beteiligungsgesellschaft mbH
Sitz und Registergericht: Hamburg
HRB 71 153

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


More information about the oXygen-user mailing list