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: Sun, 21 Oct 2012 20:20:26 +0200
Message-ID: <CAOCxfQefQKUaOtMWCht6nSfswO_TDjFPwKYkqDf0FzWYfpoTBw@mail.gmail.com>
To: Mansour Al Akeel <mansour.alakeel@gmail.com>
Cc: xproc-dev@w3.org
Troubleshooting XProc is not too easy at the moment. You'll often be faced
with a not-so-informative error message with no reference to line number or
even which file causes the error. I'll share how I deal with debugging
though:

>From my experience:
 * it's generally a lot more difficult to debug inlined XSLTs as opposed to
XSLTs stored in separate files. So even for simple XSLTs, store them in
separate files and import them using <p:document .../> when needed.
 * if the XProc script doesn't compile or run successfully, use the
elimination method (i.e. comment out more and more of the code until it
does compile and run)
 * if it runs successfully but gives unexpected results, I pipe the parts
of the XProc that I need to inspect into a debug output port like this
(similar to what p:log does, but I'm used to doing it this way):

<p:declare-step ...>

    <p:output port="result" sequence="true">
        <p:pipe port="result" step="debug"/>
        <p:pipe port="result" step="debug-2"/>
    </p:output>

    ...

    <p:identity name="debug"/>
    <p:xslt>...</p:xslt>
    <p:identity name="debug-2"/>

    ...

</p:declare-step>


Jostein


On Sat, Oct 20, 2012 at 7:41 PM, Mansour Al Akeel <mansour.alakeel@gmail.com
> wrote:

> Thank you Jostein,
> The attachment you sent works with no issues.
> However being a newbie to xslt, I have been looking into getting my
> code to work, and find my mistake.
> This is my example, which doesn't use the directory listing function
> included with your code and it's not recursive.
>
> It shows how to pipe xslt output into another one. I like to improve
> my trouble shooting skills, and be able to
> easily my steps. May be will look into <p:log />. Not sure if there's
> a better way to see what is going on.
>
> Thank you a lot.
>
> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
> xmlns:c="http://www.w3.org/ns/xproc-step"
>                 xmlns:cx="http://xmlcalabash.com/ns/extensions"
> name="myPipeline"
> version="1.0">
>
>     <p:output port="result" sequence="true"/>
>
>     <p:variable name="path"
> select="'file:///home/mansour/workspace/test/xproc_test/xml_files/'">
>         <p:empty/>
>     </p:variable>
>
>     <p:directory-list>
>         <p:with-option name="path" select="$path">
>             <p:empty/>
>         </p:with-option>
>     </p:directory-list>
>
>     <p:for-each name="directoryloop">
>
>         <p:output port="result" sequence="true"/>
>
>         <p:iteration-source select="/c:directory/c:directory"/>
>
>         <p:variable name="dirpath"
> select="p:resolve-uri(concat(c:directory/@name, '/'),$path)"/>
>
>         <p:directory-list>
>             <p:with-option name="path" select="$dirpath"/>
>         </p:directory-list>
>
>         <p:make-absolute-uris match="c:file/@name">
>             <p:with-option name="base-uri" select="$dirpath"/>
>         </p:make-absolute-uris>
>
>         <!-- <p:identity /> -->
>
>         <p:for-each name="fileloop">
>             <p:iteration-source select="//c:file"/>
>             <p:variable name="file" select="/c:file/@name"/>
>             <p:load name="file">
>                 <p:with-option name="href" select="$file"/>
>             </p:load>
>             <!-- <p:identity /> -->
>             <p:xslt name="aggregation-step">
>                 <p:input port="parameters">
>                     <p:empty />
>                 </p:input>
>                 <p:input port="stylesheet">
>                     <p:inline>
>                         <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>                             <xsl:strip-space elements="*"/>
>                             <xsl:output method="xml" indent="yes"/>
>
>                             <xsl:template match="/" >
>                                 <ele>
>                                     <xsl:value-of select="." />
>                                 </ele>
>                             </xsl:template>
>
>                         </xsl:stylesheet>
>                     </p:inline>
>                 </p:input>
>             </p:xslt>
>             <!-- <p:wrap-sequence wrapper="message"/> -->
>         </p:for-each>
>
>         <p:wrap-sequence wrapper="root"/>
>
>     </p:for-each>
>
>     <!-- <p:xslt name="cleaning-step"> -->
>     <!--        <p:input port="parameters"> -->
>     <!--            <p:empty /> -->
>     <!--        </p:input> -->
>     <!--        <p:input port="stylesheet"> -->
>     <!--            <p:inline> -->
>     <!--                <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> -->
>     <!--                    <xsl:strip-space elements="*"/>  -->
>     <!--                    <xsl:output method="xml" indent="yes"/> -->
>     <!--                    <xsl:template match="/" > -->
>     <!--                        <cleaned> -->
>     <!--                            <xsl:apply-templates /> -->
>     <!--                        </cleaned> -->
>     <!--                    </xsl:template> -->
>     <!--                </xsl:stylesheet> -->
>     <!--            </p:inline> -->
>     <!--        </p:input> -->
>     <!-- </p:xslt> -->
>
>     <!-- Adds the time stamp and revision to the resulting XML File -->
>     <!-- and a count for the main elements in the file              -->
>     <p:xslt name="stamping-step">
>         <p:input port="parameters">
>             <p:empty />
>         </p:input>
>         <p:input port="stylesheet">
>             <p:inline>
>                 <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>                     <xsl:strip-space elements="*"/>
>                     <xsl:output method="xml" indent="yes"
> omit-xml-declaration="no"
> version="1.0" encoding="utf-8"/>
>
>                     <xsl:template match="/" >
>                         <wrapper>
>                             <xsl:text>
>                             </xsl:text>
>                             <xsl:comment>Generated on <xsl:value-of
> select="current-dateTime()"/>.</xsl:comment>
>                             <xsl:comment>Processed <xsl:value-of
> select="count(*/*)"/>.</xsl:comment>
>                             <xsl:text>
>                             </xsl:text>
>                             <xsl:apply-templates />
>                         </wrapper>
>                     </xsl:template>
>
>                 </xsl:stylesheet>
>             </p:inline>
>         </p:input>
>     </p:xslt>
> </p:declare-step>
>
>
>
>
>
> On Fri, Oct 19, 2012 at 5:41 AM, Jostein Austvik Jacobsen
> <josteinaj@gmail.com> wrote:
> > 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 Sunday, 21 October 2012 18:21:14 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 21 October 2012 18:21:14 GMT