XSL generating a summary of several files

S

shaun roe

I have a directory which contains many xml files as a result of some
analysis. I would like to have an XSL which loops over all these files
and generates a web page indicating some summary information from each
one of these files.

Is there any way of doing this in XSLT entirely, or am I forced to go to
perl/python for this kind of task? I am aware of the "document" command
in xsl but cannot see how to pipe it a whole series of files such that
one transform can loop over them.

The files all have a similar name, like JiveXML_runNumber_eventNumber.xml

cheers
shaun
 
M

Martin Honnen

shaun said:
I have a directory which contains many xml files as a result of some
analysis. I would like to have an XSL which loops over all these files
and generates a web page indicating some summary information from each
one of these files.

Is there any way of doing this in XSLT entirely, or am I forced to go to
perl/python for this kind of task? I am aware of the "document" command
in xsl but cannot see how to pipe it a whole series of files such that
one transform can loop over them.

You need to pass the file names to the document function so if you have
a static list of file names you can simply code them inside of the
stylesheet. If the list of file names is not static then you could use
some programming language like Perl or Python to create an XML document
with the file names and read that document in with the XSLT document
function.
 
P

Peter Flynn

Martin said:
You need to pass the file names to the document function so if you have
a static list of file names you can simply code them inside of the
stylesheet. If the list of file names is not static then you could use
some programming language like Perl or Python to create an XML document
with the file names and read that document in with the XSLT document
function.

Or perhaps write 2-3 lines of {your favourite scripting language} to
output the list of filenames you want to process into a temporary XML
file, eg

<files>
<file>foo.xml</file>
<file>bar.xml</file>
...
</files>

Then access that from within your XSLT program using document().

///Peter
 
J

Joe Kesselman

Or, if you don't want to generate a "script" file, pass in a list of
files as a stylesheet parameter and do the string processing necessary
to parse it into separate filenames/URIs you can call document() on.
 
G

George Bina

If you use Saxon 8 then you can use the collection funtion to process
the files from a directory. For example the following stylesheet

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<result>
<xsl:for-each select="collection('.?recurse=no;select=*.xml')">
<xsl:copy-of select="."/>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>

copies all the XML files content from the current directory inside a
"result" element.

Best Regards,
George
 

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

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top