newbie : processing a folder filled with xml-files

Discussion in 'XML' started by Koen Wybo, Jun 10, 2004.

  1. Koen Wybo

    Koen Wybo Guest

    I'm rather new to xml/xslt.
    I'm looking for a possibility to proces a folder filled with xml-files
    with XSLT. Don't know if this is possible.
    In the folder are hundreds of xml-files (with same DTD-structure).
    Do know that
    <xsl:for-each select="document('first.xml') / |
    document('second.xml') /"> processes all the files that are named. But how
    can you do this with a folder (without knowing the names of the
    files except that it ends with .xml)?

    Koen Wybo
    Koen Wybo, Jun 10, 2004
    #1
    1. Advertising

  2. Koen Wybo <> wrote:
    > I'm rather new to xml/xslt.
    > I'm looking for a possibility to proces a folder filled with xml-files
    > with XSLT. Don't know if this is possible.
    > In the folder are hundreds of xml-files (with same DTD-structure).
    > Do know that
    > <xsl:for-each select="document('first.xml') / |
    > document('second.xml') /"> processes all the files that are named. But how
    > can you do this with a folder (without knowing the names of the
    > files except that it ends with .xml)?


    There's always a script way of doing it, which is something that you can
    do with 10000000 different tools.

    Do you want to process each of them separately or plop them all into one
    big document? The former is a bit easier than the latter.

    The following assumes unix.

    For a very ugly, but prototypable, way to do the former:

    ls *.xml | awk '{print("process this "$1)}' | /bin/bash

    Substitute "process this" with whatever command you want to use. Omit
    the | /bin/bash (or whatever shell) until you have it right.

    For example (I could remove the .xml from the filename, but I'm tired,
    so I won't):

    ls *.xml | awk '{print("/usr/local/bin/fop/fop.sh -xml "$1" -xsl my.xsl
    -pdf "$1".pdf")}' | /bin/bash

    --
    _Deirdre http://deirdre.net
    "Memes are a hoax! Pass it on!"
    Deirdre Saoirse Moen, Jun 10, 2004
    #2
    1. Advertising

  3. In article <>,
    Koen Wybo <> wrote:

    [...]

    % <xsl:for-each select="document('first.xml') / |
    % document('second.xml') /"> processes all the files that are named. But how
    % can you do this with a folder (without knowing the names of the
    % files except that it ends with .xml)?

    You can't, without going outside xslt. One way would be to generate
    this list to start with:

    echo '<files>' > file.dir
    for a in *.xml
    do
    echo ' <file>'$a'</file>' >> file.dir
    done
    echo '</files>' >> file.dir

    xsltproc file.xsl file.dir

    file.xsl would contain something like

    <xsl:template match='file'>
    <xsl:for-each select="document(.)">
    ...
    </xsl:for-each>
    </xsl:template>

    with ... being replaced by whatever you currently do with the output
    of document().

    If your xslt process supports extension, you can write an extension
    function to return this information from within the style sheet.

    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Jun 11, 2004
    #3
  4. /Patrick TJ McPhee/:

    > You can't, without going outside xslt. One way would be to generate
    > this list to start with:

    [...]

    One could use Ant's <http://ant.apache.org/> "Xslt/Style" task
    <http://ant.apache.org/manual/CoreTasks/style.html>.

    --
    Stanimir
    Stanimir Stamenkov, Jun 11, 2004
    #4
  5. Koen Wybo

    Rolf Magnus Guest

    Patrick TJ McPhee wrote:

    > echo '<files>' > file.dir
    > for a in *.xml
    > do
    > echo ' <file>'$a'</file>' >> file.dir
    > done
    > echo '</files>' >> file.dir
    >
    > xsltproc file.xsl file.dir
    >
    > file.xsl would contain something like
    >
    > <xsl:template match='file'>
    > <xsl:for-each select="document(.)">
    > ...
    > </xsl:for-each>
    > </xsl:template>
    >
    > with ... being replaced by whatever you currently do with the output
    > of document().


    Or you could use XInclude.

    echo '<files xmlns:xi="http://www.w3.org/2001/XInclude">' > file.dir
    for a in *.xml
    do
    echo ' <xi:include href="'$a'"/>' >> file.dir
    done
    echo '</files>' >> file.dir

    xsltproc --xinclude file.xsl file.dir
    Rolf Magnus, Jun 11, 2004
    #5
  6. Rolf Magnus <> wrote in message news:<cac4i3$qf4$01$-online.com>...
    > Patrick TJ McPhee wrote:
    >
    > > echo '<files>' > file.dir
    > > for a in *.xml
    > > do
    > > echo ' <file>'$a'</file>' >> file.dir
    > > done
    > > echo '</files>' >> file.dir
    > >
    > > xsltproc file.xsl file.dir
    > >
    > > file.xsl would contain something like
    > >
    > > <xsl:template match='file'>
    > > <xsl:for-each select="document(.)">
    > > ...
    > > </xsl:for-each>
    > > </xsl:template>
    > >
    > > with ... being replaced by whatever you currently do with the output
    > > of document().

    >
    > Or you could use XInclude.
    >
    > echo '<files xmlns:xi="http://www.w3.org/2001/XInclude">' > file.dir
    > for a in *.xml
    > do
    > echo ' <xi:include href="'$a'"/>' >> file.dir
    > done
    > echo '</files>' >> file.dir
    >
    > xsltproc --xinclude file.xsl file.dir


    the first example works for me with saxon but not with xsltproc.
    xsltproc -V gives me
    using libxml 20610, libxslt 10107 and libexslt 805

    what result should the second example give?
    how does it works?
    i have read the tutorial on www.zvon.org but did not get results.

    greetings
    michael
    Michael TEpperis, Jun 17, 2004
    #6
  7. Koen Wybo

    Rolf Magnus Guest

    Michael TEpperis wrote:

    > Rolf Magnus <> wrote in message
    > news:<cac4i3$qf4$01$-online.com>...
    >> Patrick TJ McPhee wrote:
    >>
    >> > echo '<files>' > file.dir
    >> > for a in *.xml
    >> > do
    >> > echo ' <file>'$a'</file>' >> file.dir
    >> > done
    >> > echo '</files>' >> file.dir
    >> >
    >> > xsltproc file.xsl file.dir
    >> >
    >> > file.xsl would contain something like
    >> >
    >> > <xsl:template match='file'>
    >> > <xsl:for-each select="document(.)">
    >> > ...
    >> > </xsl:for-each>
    >> > </xsl:template>
    >> >
    >> > with ... being replaced by whatever you currently do with the
    >> > output of document().

    >>
    >> Or you could use XInclude.
    >>
    >> echo '<files xmlns:xi="http://www.w3.org/2001/XInclude">' >
    >> file.dir for a in *.xml
    >> do
    >> echo ' <xi:include href="'$a'"/>' >> file.dir
    >> done
    >> echo '</files>' >> file.dir
    >>
    >> xsltproc --xinclude file.xsl file.dir

    >
    > the first example works for me with saxon but not with xsltproc.
    > xsltproc -V gives me
    > using libxml 20610, libxslt 10107 and libexslt 805


    Mine says:
    Using libxml 20510, libxslt 10032 and libexslt 721

    > what result should the second example give?
    > how does it works?


    xinclude is a standard for including any well-formed xml document into
    another xml document by doing something like:

    <xi:include href="somefile.xml"/>

    Try this:

    xinclude.xml:

    <?xml version="1.0"?>
    <test xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:include href="xinclude2.xml"/>
    </test>

    xinclude2.xml:

    <?xml version="1.0">
    <something>
    <blah/>
    </something>

    And now run it through xmllint --xinclude xinclude.xml
    Rolf Magnus, Jun 17, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio D'Ottavio
    Replies:
    1
    Views:
    2,714
    Antonio D'Ottavio
    Sep 19, 2005
  2. John Saunders
    Replies:
    0
    Views:
    712
    John Saunders
    Aug 29, 2003
  3. Bomb Diggy
    Replies:
    0
    Views:
    440
    Bomb Diggy
    Jul 28, 2004
  4. Replies:
    7
    Views:
    394
    Gabriel Genellina
    Sep 25, 2007
  5. Replies:
    0
    Views:
    136
Loading...

Share This Page