W3C home > Mailing lists > Public > xproc-dev@w3.org > October 2012

Re: Processing files in multiple directories

From: Jostein Austvik Jacobsen <josteinaj@gmail.com>
Date: Fri, 19 Oct 2012 11:41:39 +0200
Message-ID: <CAOCxfQf+M6JpQF=s-858kTbY9MB45h=TbYAi4wgvcBKUMqV-5A@mail.gmail.com>
To: Mansour Al Akeel <mansour.alakeel@gmail.com>
Cc: xproc-dev@w3.org
I've attached an example that iterates recursively through a directory of
XML files, loads them, applies an XSLT transform, combines them and outputs
in on the primary output port.

Here's an example of how to do recursive directory listing:
http://xproc.org/library/recursive-directory-list.xpl
It will give you something like this:
<c:directory xmlns:c="http://www.w3.org/ns/xproc-step" name="dir"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/">
    <c:directory name="dir1"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir1/">
        <c:file name="1.xml"/>
        <c:file name="2.xml"/>
    </c:directory>
    <c:directory name="dir2"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir2/">
        <c:file name="3.xml"/>
        <c:file name="4.xml"/>
    </c:directory>
</c:directory>

If you then run <p:add-xml-base all="true" relative="false"/> on it, you'll
get something that's easier to work with:
<c:directory xmlns:c="http://www.w3.org/ns/xproc-step" name="dir"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/">
    <c:directory name="dir1"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir1/">
        <c:file name="1.xml"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir1/"/>
        <c:file name="2.xml"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir1/"/>
    </c:directory>
    <c:directory name="dir2"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir2/">
        <c:file name="3.xml"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir2/"/>
        <c:file name="4.xml"
xml:base="file:/home/jostein/Skrivebord/xproc-subdir-xslt/dir/dir2/"/>
    </c:directory>
</c:directory>

Then simply iterate through all the c:file elements, resolve the @name
against @xml:base to get the full URI to the files, load the files and
apply the XSLT you want:
<p:for-each>
    <p:iteration-source select="//c:file"/>
    <p:variable name="href" select="p:resolve-uri(/*/@name,/*/@xml:base)"/>
    <p:load>
        <p:with-option name="href" select="$href"/>
    </p:load>
    <p:xslt>
        <p:input port="parameters">
            <p:empty/>
        </p:input>
        <p:input port="stylesheet">
            <p:document href="beverage.xslt"/>
        </p:input>
    </p:xslt>
</p:for-each>


Hope this helps. :)

Jostein


On Fri, Oct 19, 2012 at 1:40 AM, Mansour Al Akeel <mansour.alakeel@gmail.com
> wrote:

> I am new to Xproc, and by reading about it, I thought it can be help
> me making things cleaner.
> I have many xml files in 3 directories. These files have to pass an
> XSLT transformation. The results is aggregated into one single file
> and a root node is added.
> This is currently done with the help of Java. Then the resulting file
> has to go through multiple XSLTs before getting the final results.
>
> I found this article useful, showing how to use p:directory-list
>
>
> http://www.proxml.be/users/paul/weblog/1722f/Directory_listings_in_XProc.html
>
>
> But then how do I apply a transformation for each file in a loop, and
> send the results to the rest of the style sheets ??
>
> Thank you in advance.
>
>
>


Received on Friday, 19 October 2012 09:42:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 19 October 2012 09:42:30 GMT