Re: [basex-talk] Destination of result-document from XSLT module

2015-08-03 Thread Max Goltzsche

Hello Vincent,

besides an URI resolver I also want to set XSLT 2.0's output destination 
in BaseX.
Currently as you can see in BaseX' xslt:transform and 
xslt:transform-text implementation in 
https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/query/func/xslt/XsltTransform.java 
there is neither an URIResolver or OutputURIResolver set on the 
Transformer nor a destination systemId set on its StreamResult. Thus 
Saxon resolves output paths relative to your Java process' working 
directory (in fact all relative XSL include, import, document and 
collection paths in the XSLT passed to the transform method).
Unfortunately to change this behaviour the XsltTransform class must be 
enhanced.
If you need a quicker* solution for your problem you may have to build 
your own BaseX transform Java Module based on the XsltTransform class 
setting at least the StreamResult's systemId I think.

I will be also working on this the next evenings.

best regards,
Max

On 03.08.2015 20:54, Lizzi, Vincent wrote:


I’m trying to use the XSLT Module in BaseX 8.2.3 with Saxon 9.6 to run 
an XSLT that produces several output documents using 
xsl:result-document. I’m having trouble setting the location of the 
output documents. I want to have xsl:result-document create the output 
documents in a temporary folder because the documents need to be 
zipped together.


According to Saxon’s documentation, the a relative path in the href 
attribute of xsl:result-document will be resolved using either the 
path of the Destination, or the current directory. The XSLT Module 
does not appear have a way to provide a path for a destination 
document.  What I’m seeing is that the result documents are created in 
BaseX’s home directory. The XSLT works as expected when run using 
Saxon from the command line, where it’s possible to set a destination 
path.


Is there a way to specify a Base Output URI to the XSLT Module? Or, 
would it be possible to specify a file URI output location to a method 
like xslt:transform?


One possible workaround is to provide an absolute path as a parameter 
to the XSLT, and use that parameter in the xsl:result-document href 
location.


Here is a self-contained example code:

declare function local:example($in, $xsl, $zipPath) {

  let $tempDir := file:create-temp-dir('test', 'example')

  let $x := xslt:transform-text($in, $xsl)

  return

let $zip := archive:create-from($tempDir)

return (

  file:write-binary($zipPath, $zip)

  (: , file:delete($tempDir, true()) :)

)

};

let $xsl := xsl:stylesheet 
xmlns:xsl=http://www.w3.org/1999/XSL/Transform; 
xmlns:xs=http://www.w3.org/2001/XMLSchema; version=2.0


xsl:template match=/

xsl:result-document href=doc1.xml

testthis is a test 1 xsl:apply-templates//test

/xsl:result-document

xsl:result-document href=doc2.xml

testthis is a test 2 xsl:apply-templates//test

/xsl:result-document

/xsl:template

/xsl:stylesheet

let $doc := testthis is input/test

let $zipPath := 'report.zip'

return local:example($doc, $xsl, $zipPath)

The expected output is a zip file report.zip that contains doc1.xml 
and doc2.xml.


However, what I’m seeing is that report.zip is created as an empty zip 
file and doc1.xml and doc2.xml are placed in BaseX’s home directory.


Thanks,

Vincent





[basex-talk] Custom URI resolver

2015-07-25 Thread Max Goltzsche

Hello,

I want to import a XSL transformation into another by name as it is 
already possible with XQuery modules - a pitty that this doesn't work 
with XSL transformations imported via expath package.
Furthermore I want to restrict file system access in XSL transformations 
and xqueries.
As far as I understand it to do both I need to define a custom URI 
resolver - Please tell me if there is a better way.
Thus my question is: How can I register a central URI resolver to be 
used by both XSLT and XQuery?


I work with BaseX 8.2.3 and Saxon-HE 9.6.0-6 directly with Context and 
LocalSession objects in Java.


I've read http://docs.basex.org/wiki/Catalog_Resolver and registered a 
catalog file via SET CATFILE but it doesn't seem to be used in XSL 
transformations. I've also tried it with Apache XML resolver in the 
classpath. For Saxon I tried to register the CatalogResolver explicitly 
by setting the system property 
http://saxon.sf.net/feature/uriResolverClass to 
org.apache.xml.resolver.tools.CatalogResolver and writing a 
CatalogManager.properties file without effect.


What is missing? Please help!

Best regards,
Max