newbie : processing a folder filled with xml-files

Koen Wybo

Usenet Archive
Joined
Jun 10, 2004
Messages
1
Reaction score
0
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
 

Deirdre Saoirse Moen

Usenet Archive
Joined
May 20, 2004
Messages
14
Reaction score
0
Koen Wybo said:
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
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
[...]

% <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.
 

Rolf Magnus

Usenet Archive
Joined
Jun 25, 2003
Messages
3,487
Reaction score
0
Patrick said:
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
 

Michael TEpperis

Usenet Archive
Joined
May 17, 2004
Messages
8
Reaction score
0
Rolf Magnus said:
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
 

Rolf Magnus

Usenet Archive
Joined
Jun 25, 2003
Messages
3,487
Reaction score
0
Michael said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top