Page 1 of 1

The URI http://expath.org/ns/file does not identify an external Java class

Posted: Tue Mar 24, 2020 11:07 pm
by stran
Hi,

we are using our own version of maketoc and chunktoc (xslt 1). When we execute chunktoc, we have a template that copy a file into another place. Exemple:

Code: Select all

xmlns:file="http://expath.org/ns/file"
    exclude-result-prefixes="file" version="1.0"
    
    
<xsl:template match="imagedata[@fileref='babyyoda.jpg']">
        <xsl:value-of select="file:copy('C:\Users\stran\Documents\testarticle\babyyoda.jpg', 'C:\Users\stran\Documents\testarticle\assoc\babyyoda.jpg')"/>
    </xsl:template>
Chunktoc uses Saxon 6.5.5. But when we try to execute the chuntoc, it displays this message:
The URI http://expath.org/ns/file does not identify an external Java class

Is there a way to copy without having to switch from saxon (we're very dependant on it)?

Re: The URI http://expath.org/ns/file does not identify an external Java class

Posted: Wed Mar 25, 2020 5:35 pm
by adrian
Hello,

You seem to be using an EXPath extension module (http://expath.org/ns/file), but AFAIK, there is no such an implementation of EXPath for Saxon 6.5.5. EXPath is available in Saxon 9. The EXPath file module is built into Saxon since 9.5 (available in Saxon-PE and Saxon-EE).

As an alternative you could copy the file by using reflexive extension functions in Java. Like this (using Apache Commons IO):

Code: Select all

  xmlns:file="java:java.io.File"
  xmlns:fileutils="java:org.apache.commons.io.FileUtils"
  exclude-result-prefixes="file fileutils"
  version="1.0">
  
  <xsl:template match="imagedata[@fileref='babyyoda.jpg']">
    <xsl:value-of select="fileutils:copyFile(file:new('C:\Users\stran\Documents\testarticle\babyyoda.jpg'), file:new('C:\Users\stran\Documents\testarticle\assoc\babyyoda.jpg'))"/>
  </xsl:template>
Note that this requires the class org.apache.commons.io.FileUtils from Apache Commons IO, so you also need the commons-io-*.jar in the classpath.

Regards,
Adrian

Re: The URI http://expath.org/ns/file does not identify an external Java class

Posted: Wed Mar 25, 2020 8:38 pm
by stran
It's giving me the message:

There are several Java methods that match equally well

Re: The URI http://expath.org/ns/file does not identify an external Java class

Posted: Wed Mar 25, 2020 10:59 pm
by stran
I forgot to add file:new! It works thanks!