W3C home > Mailing lists > Public > xproc-dev@w3.org > November 2011

Re: The file name for the output of an xsl:result-document

From: David Cramer <david@thingbag.net>
Date: Thu, 03 Nov 2011 16:44:25 -0500
Message-ID: <4EB30B39.1040105@thingbag.net>
To: xproc-dev@w3.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ah, I'm starting to get it. Now I"ve got it doing exactly what I want.

I've pasted the pipeline I ended up with below in case anybody else
happens on this thread and wants to know how make the output file land
in a directory relative to the input file and also make the files
produced by xsl:result-document land in the same place.

In my case, the pipeline/xslt takes a single wadl file as input and
produces a flattened wadl file and a number of flattened xsds. It also
validates the input and output wadls against a schema, though it just
occurred to me that I still need to add a step so that it validates
the output schemas as well.

Thanks so much for all your help!

David

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
    version="1.0">
    <p:input port="source"/>
    <p:output port="secondary" primary="false" sequence="true"/>

    <p:variable name="input-base" select="replace(base-uri(/*),
'^(.*/)?([^/]+)$', '$1')"/>
    <p:variable name="input-name" select="replace(base-uri(/*),
'^(.*/)?([^/]+)$', '$2')"/>
    <p:variable name="output-wadl"
select="resolve-uri(concat('normalized/',$input-name), $input-base)"/>

    <p:validate-with-xml-schema assert-valid="true" mode="strict"
name="validate">
        <p:input port="schema">
            <p:document  href="xsd/wadl.xsd"/>
        </p:input>
    </p:validate-with-xml-schema>

    <p:xslt name="style" version="2.0">
        <p:input port="source">
            <p:pipe step="validate" port="result"/>
        </p:input>
        <p:input port="stylesheet">
            <p:document href="xsl/normalizeWadl.xsl"/>
        </p:input>
        <p:input port="parameters">
            <p:empty/>
        </p:input>
    </p:xslt>

    <p:validate-with-xml-schema assert-valid="true" mode="strict"
name="post-validate">
        <p:input port="schema">
            <p:document  href="xsd/wadl.xsd"/>
        </p:input>
    </p:validate-with-xml-schema>

    <p:store>
        <p:with-option name="href" select="$output-wadl"/>
        <p:log port="result" href="xproc1.log"/>
    </p:store>

    <p:for-each>
        <p:iteration-source>
            <p:pipe step="style" port="secondary"/>
        </p:iteration-source>
        <p:store encoding="utf-8" indent="true"
omit-xml-declaration="false">
            <p:with-option name="href"
select="resolve-uri(concat('normalized/',replace(base-uri(/*),
'^(.*/)?([^/]+)$', '$2')),$input-base)"/>
        </p:store>
    </p:for-each>

</p:declare-step>

On 11/03/2011 10:34 AM, Geert Josten wrote:
> Hi David,
> 
> AVTs are indeed not supported, unfortunately. You will have to use
>  p:with-output for passing in a variable as well.
> 
> <p:store> <p:with-option name="href" select="$output-wadl"/> 
> </p:store>
> 
> The second store doesn't work, because resolve-uri only prepends a 
> base if the first argument represents a relative path. By
> supplying base-uri(/*) you are passing in an absolute path, so
> resolve-uri won't work. You can grab the last part of the path
> using a replace:
> 
> replace(base-uri(/*), '^(.*/)?([^/]+)$', '$2')
> 
> Kind regards, Geert
> 
> -----Oorspronkelijk bericht----- Van: David Cramer 
> [mailto:david@thingbag.net] Verzonden: donderdag 3 november 2011 
> 15:43 Aan: XProc Dev Onderwerp: Re: The file name for the output
> of an xsl:result-document
> 
> Thanks Geert and Vojtech,
> 
> At the top of the file I've tried various versions of:
> 
> <p:variable name="input-base" select="p:base-uri(/*)"/>
> <p:variable name="output-wadl"
> select="p:resolve-uri('foo.xml',$input-base)"/>
> 
> Then to store the main result document, I want to use the value of
>  variable, but clearly AVTs aren't the way to do it:
> 
> <p:store href="{$output-wadl}"/>
> 
> Likewise, for the documents on the secondary port, using 
> resolve-uri (or p:resolve-uri) doesn't have any effect:
> 
> <p:with-option name="href" 
> select="resolve-uri(base-uri(/*),$input-base)"/>
> 
> I've put the whole listing here:
> 
> http://pastebin.com/3dQzsQ2b
> 
> What am I doing wrong?
> 
> I feel like I'm struggling with very basic things. Aside from the 
> spec, is there a good xproc reference or tutorial that would help 
> with these questions? I've googled up a few things, but nothing 
> that that seems comprehensive. The best thing I've found so far is:
> http://www.xfront.com/xproc/
> 
> Thanks, David
> 
> On 11/03/2011 06:09 AM, Geert Josten wrote:
>> Hi David,
> 
>> Sounds like you want to put a p:variable at the top of your 
>> pipeline/declare-step, do the base-uri(/) or base-uri(/*) there.
>>  That takes the base-uri of the input, instead of the generated 
>> output. Then use resolve-uri('foo.xml', $input-base-uri) to get a
>> path for foo.xml in the input folder..
> 
>> Kind regards, Geert
> 
>> -----Oorspronkelijk bericht----- Van: David Cramer 
>> [mailto:david@thingbag.net] Verzonden: donderdag 3 november 2011
>>  3:06 Aan: Geert Josten CC: XProc Dev Onderwerp: Re: The file 
>> name for the output of an xsl:result-document
> 
>> Thanks Geert. That helped. Using p:log, I learned that 
>> base-uri(/*) causes the files land in my home directory with 
>> their appropriate file names.
> 
>> Now I just need to figure out how to say in xproc "In the same 
>> directory as the source document" (or in some dir passed in from
>>  Oxygen anyway). E.g. here:
> 
>> <p:store href="concat(???, '/', 'foo.xml')"/>
> 
>> and here:
> 
>> <p:with-option name="href" select="concat( ???, '/', 
>> p:base-uri(/*))"/>
> 
>> Though I could be going about it all wrong.
> 
>> Thanks, David
> 
>> On 11/01/2011 04:10 PM, Geert Josten wrote:
>>> Hi David,
> 
>>> Bit of a guess here, but have you tried base-uri(/*) ?
> 
>>> Kind regards, Geert
> 
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOsws5AAoJEMHeSXG7afUhulAH/R1JcegfSYKnCLICXFohoI3/
zElKKbXqtfQmthjGEDrqqbqtzv0EQR40gbSAtw28yf9XtuVMYXXS62Y1IvqbisnT
nMUSnuD/FPtGEzGNq4ULfhfungvv5uQO3/SDvsb6/E4M0k7YNuytcdtGZEpu/uKF
2BECsYiedLSV1Q9FHwaSqTYVQjEQVe1RdFuitEPg+xNYjoYG/H5STrXVnkoWFg81
KERPpZj0zjWANBhbq8/MUDgU39qw75vKFU0YlI61l4sx6U3Mu/ojE9gx+cMDWN+O
cRBDEBHHNv6yA1ATimTiEY5mMcMdFLMUBwvhGRMIJ29gzM7VnMQ+wz/DrPOV2Z8=
=N60o
-----END PGP SIGNATURE-----
Received on Thursday, 3 November 2011 21:45:02 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 3 November 2011 21:45:04 GMT