Destination of result-document from XSLT module

Monday, 3 August 2015 · 8 messages · last reply 5 Aug 2015
LV
Lizzi, Vincent3 Aug 2015 20:54 #
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">
            <test>this is a test 1 <xsl:apply-templates/></test>
        </xsl:result-document>
        <xsl:result-document href="doc2.xml">
            <test>this is a test 2 <xsl:apply-templates/></test>
        </xsl:result-document>
    </xsl:template>
</xsl:stylesheet>

let $doc := <test>this 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
MG
Max Goltzsche3 Aug 2015 21:54 #
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
Quoted text · Vincent · 86 lines
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"> > > <test>this is a test 1 <xsl:apply-templates/></test> > > </xsl:result-document> > > <xsl:result-document href="doc2.xml"> > > <test>this is a test 2 <xsl:apply-templates/></test> > > </xsl:result-document> > > </xsl:template> > > </xsl:stylesheet> > > let $doc := <test>this 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 >
AB
Andy Bunce3 Aug 2015 22:32 #
Hi Max, This sounds like a good thing. Another solution to the result-document issue might be to implement the XQuery 3.1 transform function [1] /Andy [1] http://www.w3.org/TR/xpath-functions-31/#func-transform
Quoted text · Max Goltzsche · 139 lines
On 3 August 2015 at 20:54, Max Goltzsche <max.goltzsche at algorythm.de> wrote: > 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" > <http://www.w3.org/1999/XSL/Transform> xmlns:xs= > "http://www.w3.org/2001/XMLSchema" <http://www.w3.org/2001/XMLSchema> > version="2.0"> > > <xsl:template match="/"> > > <xsl:result-document href="doc1.xml"> > > <test>this is a test 1 <xsl:apply-templates/></test> > > </xsl:result-document> > > <xsl:result-document href="doc2.xml"> > > <test>this is a test 2 <xsl:apply-templates/></test> > > </xsl:result-document> > > </xsl:template> > > </xsl:stylesheet> > > > > let $doc := <test>this 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 > > >
M
Marc3 Aug 2015 22:52 #
Hi, I have an other problem is to control the serialization of the node passed to the transform function. I don't see how to control it. Marc
Quoted text · Andy Bunce · 155 lines
Le 03/08/2015 22:32, Andy Bunce a écrit : > Hi Max, > This sounds like a good thing. > Another solution to the result-document issue might be to implement the > XQuery 3.1 transform function [1] > > /Andy > [1] http://www.w3.org/TR/xpath-functions-31/#func-transform > > On 3 August 2015 at 20:54, Max Goltzsche <max.goltzsche at algorythm.de > <mailto:max.goltzsche at algorythm.de>> wrote: > > 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" > > <http://www.w3.org/1999/XSL/Transform> > > xmlns:xs="http://www.w3.org/2001/XMLSchema" > > <http://www.w3.org/2001/XMLSchema> version="2.0">____ > > > > <xsl:template match="/">____ > > > > <xsl:result-document href="doc1.xml">____ > > > > <test>this is a test 1 <xsl:apply-templates/></test>____ > > > > </xsl:result-document>____ > > > > <xsl:result-document href="doc2.xml">____ > > > > <test>this is a test 2 <xsl:apply-templates/></test>____ > > > > </xsl:result-document>____ > > > > </xsl:template>____ > > > > </xsl:stylesheet>____ > > > > __ __ > > > > let $doc := <test>this 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____ > > > >
LV
Lizzi, Vincent3 Aug 2015 23:07 #
Thanks, Max and Andy. The XQuery 3.1 transform function looks promising. Marc, For controlling the serialization of XSLT output, you can specify serialization for the XSLT within the XSLT itself using xsl:output, run the XSLT using the xslt:transform-text, and then write the output to a file.
file:write-text('file.txt', xslt:transform-text($doc, $xslt))
I'm not sure if this will do what you need, but so far it has been working for me. Vincent
Quoted text · Marc · 166 lines
-----Original Message----- From: basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] On Behalf Of Marc Sent: Monday, August 03, 2015 4:53 PM Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Destination of result-document from XSLT module Hi, I have an other problem is to control the serialization of the node passed to the transform function. I don't see how to control it. Marc Le 03/08/2015 22:32, Andy Bunce a écrit : > Hi Max, > This sounds like a good thing. > Another solution to the result-document issue might be to implement > the XQuery 3.1 transform function [1] > > /Andy > [1] http://www.w3.org/TR/xpath-functions-31/#func-transform > > On 3 August 2015 at 20:54, Max Goltzsche <max.goltzsche at algorythm.de > <mailto:max.goltzsche at algorythm.de>> wrote: > > 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" > > <http://www.w3.org/1999/XSL/Transform> > > xmlns:xs="http://www.w3.org/2001/XMLSchema" > > <http://www.w3.org/2001/XMLSchema> version="2.0">____ > > > > <xsl:template match="/">____ > > > > <xsl:result-document href="doc1.xml">____ > > > > <test>this is a test 1 > > <xsl:apply-templates/></test>____ > > > > </xsl:result-document>____ > > > > <xsl:result-document href="doc2.xml">____ > > > > <test>this is a test 2 > > <xsl:apply-templates/></test>____ > > > > </xsl:result-document>____ > > > > </xsl:template>____ > > > > </xsl:stylesheet>____ > > > > __ __ > > > > let $doc := <test>this 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____ > > > >
M
Marc3 Aug 2015 23:48 #
Thank Vincent, But it the input of the xslt I want to control. I'm using BaseX with the CHOP false because I use text documentation and space is important at the end or the begining of an element, and when I try to use xslt (with baseX 7) it serialize with indent true the input of my xslt, so I lost the space. Marc
Quoted text · Vincent · 180 lines
Le 03/08/2015 23:07, Lizzi, Vincent a écrit : > Thanks, Max and Andy. The XQuery 3.1 transform function looks promising. > > Marc, For controlling the serialization of XSLT output, you can specify serialization for the XSLT within the XSLT itself using xsl:output, run the XSLT using the xslt:transform-text, and then write the output to a file. > > file:write-text('file.txt', xslt:transform-text($doc, $xslt)) > > I'm not sure if this will do what you need, but so far it has been working for me. > > Vincent > > > > -----Original Message----- > From: basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] On Behalf Of Marc > Sent: Monday, August 03, 2015 4:53 PM > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Destination of result-document from XSLT module > > Hi, > I have an other problem is to control the serialization of the node passed to the transform function. > I don't see how to control it. > Marc > Le 03/08/2015 22:32, Andy Bunce a écrit : > > Hi Max, > > This sounds like a good thing. > > Another solution to the result-document issue might be to implement > > the XQuery 3.1 transform function [1] > > > > /Andy > > [1] http://www.w3.org/TR/xpath-functions-31/#func-transform > > > > On 3 August 2015 at 20:54, Max Goltzsche <max.goltzsche at algorythm.de > > <mailto:max.goltzsche at algorythm.de>> wrote: > > > > 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" > >> <http://www.w3.org/1999/XSL/Transform> > >> xmlns:xs="http://www.w3.org/2001/XMLSchema" > >> <http://www.w3.org/2001/XMLSchema> version="2.0">____ > >> > >> <xsl:template match="/">____ > >> > >> <xsl:result-document href="doc1.xml">____ > >> > >> <test>this is a test 1 > >> <xsl:apply-templates/></test>____ > >> > >> </xsl:result-document>____ > >> > >> <xsl:result-document href="doc2.xml">____ > >> > >> <test>this is a test 2 > >> <xsl:apply-templates/></test>____ > >> > >> </xsl:result-document>____ > >> > >> </xsl:template>____ > >> > >> </xsl:stylesheet>____ > >> > >> __ __ > >> > >> let $doc := <test>this 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____ > >> > > > >
LV
Lizzi, Vincent5 Aug 2015 03:45 #
Marc, Thanks for mentioning that! I am running into problems with whitespace being lost on input to the transformation too. For example, an XSLT contains inside a template:
<t>within the past <xsl:value-of select="$days"/> days</t>
The output has lost the whitespace around the <xsl:value-of> element: within the past15days Set CHOP false before the transformation helps, for example:
(# db:chop false #) { let $xslt := doc('stylesheet.xsl') return xslt:transform-text($doc, $xslt) }
Provides the expected output: within the past 15 days I will have to watch for other instances of lost whitespace in documents. In regard to my original question about setting Base Output URI, the solution I've chosen for now is to pass a URI path to a folder as a parameter into the stylesheet, and update each xsl:result-document href attribute to include the parameter value.
<xsl:param name="base-output-uri" select="''"/>

<xsl:result-document href="{$base-output-uri}doc1.xml">
Thanks, Vincent
Quoted text · Marc · 191 lines
-----Original Message----- From: basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] On Behalf Of Marc Sent: Monday, August 03, 2015 5:49 PM Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Destination of result-document from XSLT module Thank Vincent, But it the input of the xslt I want to control. I'm using BaseX with the CHOP false because I use text documentation and space is important at the end or the begining of an element, and when I try to use xslt (with baseX 7) it serialize with indent true the input of my xslt, so I lost the space. Marc Le 03/08/2015 23:07, Lizzi, Vincent a écrit : > Thanks, Max and Andy. The XQuery 3.1 transform function looks promising. > > Marc, For controlling the serialization of XSLT output, you can specify serialization for the XSLT within the XSLT itself using xsl:output, run the XSLT using the xslt:transform-text, and then write the output to a file. > > file:write-text('file.txt', xslt:transform-text($doc, $xslt)) > > I'm not sure if this will do what you need, but so far it has been working for me. > > Vincent > > > > -----Original Message----- > From: basex-talk-bounces at mailman.uni-konstanz.de > [mailto:basex-talk-bounces at mailman.uni-konstanz.de] On Behalf Of Marc > Sent: Monday, August 03, 2015 4:53 PM > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] Destination of result-document from XSLT > module > > Hi, > I have an other problem is to control the serialization of the node passed to the transform function. > I don't see how to control it. > Marc > Le 03/08/2015 22:32, Andy Bunce a écrit : > > Hi Max, > > This sounds like a good thing. > > Another solution to the result-document issue might be to implement > > the XQuery 3.1 transform function [1] > > > > /Andy > > [1] http://www.w3.org/TR/xpath-functions-31/#func-transform > > > > On 3 August 2015 at 20:54, Max Goltzsche <max.goltzsche at algorythm.de > > <mailto:max.goltzsche at algorythm.de>> wrote: > > > > 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" > >> <http://www.w3.org/1999/XSL/Transform> > >> xmlns:xs="http://www.w3.org/2001/XMLSchema" > >> <http://www.w3.org/2001/XMLSchema> version="2.0">____ > >> > >> <xsl:template match="/">____ > >> > >> <xsl:result-document href="doc1.xml">____ > >> > >> <test>this is a test 1 > >> <xsl:apply-templates/></test>____ > >> > >> </xsl:result-document>____ > >> > >> <xsl:result-document href="doc2.xml">____ > >> > >> <test>this is a test 2 > >> <xsl:apply-templates/></test>____ > >> > >> </xsl:result-document>____ > >> > >> </xsl:template>____ > >> > >> </xsl:stylesheet>____ > >> > >> __ __ > >> > >> let $doc := <test>this 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____ > >> > > > >
CG
Christian Grün5 Aug 2015 09:34 #
Hi Vincent,
Quoted text · Lizzi, Vincent · 2 lines
> (# db:chop false #) { let $xslt := doc('stylesheet.xsl') > return xslt:transform-text($doc, $xslt) }
I should be sufficient to pass on the filename to the XSLT processor:
  xslt:transform-text($doc, 'stylesheet.xsl')
You can do the same with the document input. If you, or someone else in this discussion, is interested in extending our documentation on the specifics of our XSLT Module – which does not really cover those details yet – please don't hesitate ;) Christian

⚡Generated with XQuery