470,815 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

XSL generating a summary of several files

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
May 21 '06 #1
4 1202


shaun roe wrote:
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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
May 21 '06 #2
Martin Honnen wrote:


shaun roe wrote:
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.


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
--
XML FAQ: http://xml.silmaril.ie/
May 21 '06 #3
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.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
May 21 '06 #4
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
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

May 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.