473,509 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using document() inside a loop to get all files in a directory

What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?

more detailed:

/root
index.aspx
xsl_style.xsl
/xml
newsletter_001.xml
newsletter_002.xml
newsletter_xxx.xml
now i want to use xsl_style.xsl to pull two attributes from the root
element of each and every file in the xml directory. Something like
this:

for (each file in xml AS xmlFile)
<xsl:value-of select="document(xmlFile)//newsletter[@title]" />
<xsl:value-of select="document(xmlFile)//newsletter[@date]" />
how do i create that loop? I have to do this without a file that
contains a list of the files in the xml directory, so i need to
dynamically get the contents of the xml directory!

Thanks for your time
Jul 20 '05 #1
6 2693
Since XSLT relies heavily on optimisation all references to external
documents must be available and valid at XSLT document parse time. So ....
you can't dynamically open a document unless you know the document
filepathnames *beforehand* and either hard code them or pass them as
parameters to the document.

Dynamic folder and file recursion is *not* really suitable for XSLT - use a
script language to achieve that.

Chris.

"dSchwartz" <sc******@cableone.net> wrote in message
news:4a**************************@posting.google.c om...
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?

more detailed:

/root
index.aspx
xsl_style.xsl
/xml
newsletter_001.xml
newsletter_002.xml
newsletter_xxx.xml
now i want to use xsl_style.xsl to pull two attributes from the root
element of each and every file in the xml directory. Something like
this:

for (each file in xml AS xmlFile)
<xsl:value-of select="document(xmlFile)//newsletter[@title]" />
<xsl:value-of select="document(xmlFile)//newsletter[@date]" />
how do i create that loop? I have to do this without a file that
contains a list of the files in the xml directory, so i need to
dynamically get the contents of the xml directory!

Thanks for your time
Jul 20 '05 #2
Pass the full paths to all files as a parameter to your transformation. Then
you can access them with the document() function.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"dSchwartz" <sc******@cableone.net> wrote in message
news:4a**************************@posting.google.c om...
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?

more detailed:

/root
index.aspx
xsl_style.xsl
/xml
newsletter_001.xml
newsletter_002.xml
newsletter_xxx.xml
now i want to use xsl_style.xsl to pull two attributes from the root
element of each and every file in the xml directory. Something like
this:

for (each file in xml AS xmlFile)
<xsl:value-of select="document(xmlFile)//newsletter[@title]" />
<xsl:value-of select="document(xmlFile)//newsletter[@date]" />
how do i create that loop? I have to do this without a file that
contains a list of the files in the xml directory, so i need to
dynamically get the contents of the xml directory!

Thanks for your time

Jul 20 '05 #3
sc******@cableone.net (dSchwartz) wrote:
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?


You already got good advice, so there's just one additional hint
here.

I have solved a similar problem by creating a batch file or
shell script that parses the folder and creates an XML file
using echo commands.

In your case that XML file can contain the names of the files
and can be queried from your XSL stylesheet using import or the
document function.

Hans-Georg

--
No mail, please.
Jul 20 '05 #4
One more comment.

document() doesn't handle missing files very well - it raises a parse time
error. First time I got this I admit that I had expected it to just
gracefully gloss over and continue (shows how much I read the docs then).

I'm not saying that this behaviour is wrong but it's a bit annoying at times
and to my mind makes the XSLT a bit fragile where this particular method is
concerned.

Chris.

"dSchwartz" <sc******@cableone.net> wrote in message
news:4a**************************@posting.google.c om...
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?

more detailed:

/root
index.aspx
xsl_style.xsl
/xml
newsletter_001.xml
newsletter_002.xml
newsletter_xxx.xml
now i want to use xsl_style.xsl to pull two attributes from the root
element of each and every file in the xml directory. Something like
this:

for (each file in xml AS xmlFile)
<xsl:value-of select="document(xmlFile)//newsletter[@title]" />
<xsl:value-of select="document(xmlFile)//newsletter[@date]" />
how do i create that loop? I have to do this without a file that
contains a list of the files in the xml directory, so i need to
dynamically get the contents of the xml directory!

Thanks for your time
Jul 20 '05 #5
Thanks all for your comments. I guess I'll probably think about
storing the xml inside MS SQL server, or even just using SQL Server
instead of xml....
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message news:<#s**************@TK2MSFTNGP11.phx.gbl>...
One more comment.

document() doesn't handle missing files very well - it raises a parse time
error. First time I got this I admit that I had expected it to just
gracefully gloss over and continue (shows how much I read the docs then).

I'm not saying that this behaviour is wrong but it's a bit annoying at times
and to my mind makes the XSLT a bit fragile where this particular method is
concerned.

Chris.

"dSchwartz" <sc******@cableone.net> wrote in message
news:4a**************************@posting.google.c om...
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?

more detailed:

/root
index.aspx
xsl_style.xsl
/xml
newsletter_001.xml
newsletter_002.xml
newsletter_xxx.xml
now i want to use xsl_style.xsl to pull two attributes from the root
element of each and every file in the xml directory. Something like
this:

for (each file in xml AS xmlFile)
<xsl:value-of select="document(xmlFile)//newsletter[@title]" />
<xsl:value-of select="document(xmlFile)//newsletter[@date]" />
how do i create that loop? I have to do this without a file that
contains a list of the files in the xml directory, so i need to
dynamically get the contents of the xml directory!

Thanks for your time

Jul 20 '05 #6
OK, backtracking a bit.

I have a similar situation where I use script to create an XML document that
is the files and folders with filenames and extensions etc. (not that hard).
Once you have that you can do anything you want using XSLT and the
document() function as long as the files don't disappear.

If you keep your recursive script to generate the base XML generalised then
you can use any XSLT you want to give any form of representation of the
files and folders. In my case I am parsing for XML documents since I'm
keeping metadata about DBF files in corresponding XML files (same names) and
then using this as the basis for an ADO upload to a specific system.

Chris.
"dSchwartz" <sc******@cableone.net> wrote in message
news:4a**************************@posting.google.c om...
Thanks all for your comments. I guess I'll probably think about
storing the xml inside MS SQL server, or even just using SQL Server
instead of xml....
"Chris Barber" <ch***@blue-canoe.co.uk.NOSPAM> wrote in message
news:<#s**************@TK2MSFTNGP11.phx.gbl>...
One more comment.

document() doesn't handle missing files very well - it raises a parse time
error. First time I got this I admit that I had expected it to just
gracefully gloss over and continue (shows how much I read the docs then).

I'm not saying that this behaviour is wrong but it's a bit annoying at times and to my mind makes the XSLT a bit fragile where this particular method is concerned.

Chris.

"dSchwartz" <sc******@cableone.net> wrote in message
news:4a**************************@posting.google.c om...
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?

more detailed:

/root
index.aspx
xsl_style.xsl
/xml
newsletter_001.xml
newsletter_002.xml
newsletter_xxx.xml
now i want to use xsl_style.xsl to pull two attributes from the root
element of each and every file in the xml directory. Something like
this:

for (each file in xml AS xmlFile)
<xsl:value-of select="document(xmlFile)//newsletter[@title]" />
<xsl:value-of select="document(xmlFile)//newsletter[@date]" />
how do i create that loop? I have to do this without a file that
contains a list of the files in the xml directory, so i need to
dynamically get the contents of the xml directory!

Thanks for your time

Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3646
by: Jeff Wagner | last post by:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to getting started? Thanks, Jeff
0
1939
by: David | last post by:
Please help. I am able to display a folder structure and files but I can't figure out how to add subfolders and maintain the same look. I am a little embarrased but I thought someone out there...
3
23996
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
6551
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
4000
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
2
2022
by: dSchwartz | last post by:
I need help adding a column to a dataset, but its a little bit more complicated then just that. Here's the situation: I have many xml files in one directory, each which represent a newsletter. I...
8
6928
by: gazza67 | last post by:
Hi, I want to do something that I thought would be simple but i cant seem to work it out, perhaps someone out there could help me. I want to browse for a file (it will be a word document),...
21
34327
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
6
18202
by: mistral | last post by:
what is correct way open a PDF document in new window use hyperlink? I want show images thumbnails linked with PDF files, when click on thumbnail, PDF will be opened in new window. Some of PDF...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.