Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > using document() inside a loop to get all files in a directory

Reply
Thread Tools

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

 
 
dSchwartz
Guest
Posts: n/a
 
      03-01-2004
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
 
Reply With Quote
 
 
 
 
Chris Barber
Guest
Posts: n/a
 
      03-02-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Dimitre Novatchev [MVP XML]
Guest
Posts: n/a
 
      03-02-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
Hans-Georg Michna
Guest
Posts: n/a
 
      03-02-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
Chris Barber
Guest
Posts: n/a
 
      03-02-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
dSchwartz
Guest
Posts: n/a
 
      03-03-2004
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" <(E-Mail Removed)> wrote in message news:<#(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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

 
Reply With Quote
 
Chris Barber
Guest
Posts: n/a
 
      03-03-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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" <(E-Mail Removed)> wrote in message
news:<#(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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



 
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
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
how to loop through a directory and hyperlink to all files mrmagoo ASP .Net 6 05-06-2011 06:50 AM
Re: How to loop through a list while inside the loop, the list size may be decreased? Roedy Green Java 3 09-13-2008 01:51 AM
How do we use the file system object to loop through a directory and refresh all the files? Ajay Garg ASP General 5 01-14-2004 08:54 PM



Advertisments