Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > newbie : processing a folder filled with xml-files

Reply
Thread Tools

newbie : processing a folder filled with xml-files

 
 
Koen Wybo
Guest
Posts: n/a
 
      06-10-2004
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

 
Reply With Quote
 
 
 
 
Deirdre Saoirse Moen
Guest
Posts: n/a
 
      06-10-2004
Koen Wybo <(E-Mail Removed)> 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!"
 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      06-11-2004
In article <(E-Mail Removed)>,
Koen Wybo <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      06-11-2004
/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
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      06-11-2004
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 xmlnsi="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

 
Reply With Quote
 
Michael TEpperis
Guest
Posts: n/a
 
      06-17-2004
Rolf Magnus <(E-Mail Removed)> wrote in message news:<cac4i3$qf4$01$(E-Mail Removed)-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 xmlnsi="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
 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      06-17-2004
Michael TEpperis wrote:

> Rolf Magnus <(E-Mail Removed)> wrote in message
> news:<cac4i3$qf4$01$(E-Mail Removed)-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 xmlnsi="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 xmlnsi="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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem assigning selectedItem.Value to a dropdownlist filled with OnItemDataBound Antonio D'Ottavio ASP .Net 1 09-19-2005 09:41 AM
Post-Processing RAW vs Post-Processing TIFF Mike Henley Digital Photography 42 01-30-2005 08:26 AM
Question: processing HTML, re-write default processing action of many tags Hubert Hung-Hsien Chang Python 2 09-17-2004 03:10 PM
Re: Listbox filled with Javascript does NOT maintain viewstate John Timney \(Microsoft MVP\) ASP .Net 0 08-29-2003 05:14 PM
Re: Listbox filled with Javascript does NOT maintain viewstate John Saunders ASP .Net 0 08-29-2003 05:08 PM



Advertisments