Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 30th, 2007, 12:04 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple Input files?

Here's the dilemma - I frequently rename log files and archive them but I would now also like to audit what I've done to ensure I didn't miss anything along the way. Here is a sample of what an xml file looks like prior to initiating filename changes:

Code:
<CurrentFileNames>
  <CurrentFileName>foo1.txt</CurrentFileName>
  <CurrentFileName>foo2.txt</CurrentFileName>
  <CurrentFileName>foo3.txt</CurrentFileName>
  <CurrentFileName>foo4.txt</CurrentFileName>
  <CurrentFileName>foo5.txt</CurrentFileName>
  <CurrentFileName>foo6.txt</CurrentFileName>
  <CurrentFileName>foo7.txt</CurrentFileName>
  <CurrentFileName>foo8.txt</CurrentFileName>
</CurrentFileNames>
<UpdatedFileNames>
  <UpdatedFileName>goo1.txt</UpdatedFileName>
  <UpdatedFileName>goo2.txt</UpdatedFileName>
  <UpdatedFileName>goo3.txt</UpdatedFileName>
  <UpdatedFileName>goo4.txt</UpdatedFileName>
  <UpdatedFileName>goo5.txt</UpdatedFileName>
  <UpdatedFileName>goo6.txt</UpdatedFileName>
  <UpdatedFileName>goo7.txt</UpdatedFileName>
  <UpdatedFileName>goo8.txt</UpdatedFileName>
</UpdatedFileNames>
As you can see, it shows the current filenames and the names after renaming. We'll call this file foo.xml.

Now, AFTER renaming files, it looks somewhat like this:
Code:
<CurrentFileNames>
  <CurrentFileName>goo1.txt</CurrentFileName>
  <CurrentFileName>goo2.txt</CurrentFileName>
  <CurrentFileName>goo3.txt</CurrentFileName>
  <CurrentFileName>goo4.txt</CurrentFileName>
  <CurrentFileName>goo5.txt</CurrentFileName>
  <CurrentFileName>goo6.txt</CurrentFileName>
  <CurrentFileName>goo7.txt</CurrentFileName>
  <CurrentFileName>goo8.txt</CurrentFileName>
</CurrentFileNames>
We'll call this goo.xml.

How would I pull "UpdatedFileName" from foo.xml and "CurrentFileName" from goo.xml into a single output file? I would rather not used the document() function because the filenames are dynamic (won't always bee foo.xml & goo.xml). If using the document() function is the easiest way, then that's fine too. I can rename files before and after.

Reply With Quote
  #2 (permalink)  
Old July 30th, 2007, 03:30 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

I don't understand your objection to using the document() function. You can use it to read files whose names are supplied dynamically as stylesheet parameters. However, it's also possible to supply the documents themselves as parameters, though the details will depend on the XSLT processor you are using and its API. Typically you will be able to supply a parameter as a DOM Document node.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old July 30th, 2007, 04:36 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how would I accomplish this WITH the document()?

Reply With Quote
  #4 (permalink)  
Old July 30th, 2007, 05:02 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

You haven't said very clearly what output you want. If it's just this:

How would I pull "UpdatedFileName" from foo.xml and "CurrentFileName" from goo.xml into a single output file?

then all you need is

<xsl:copy-of select="document('foo.xml')//UpdatedFileName"/>
<xsl:copy-of select="document('goo.xml')//CurrentFileName"/>

where of course the filenames can be replaced by $doc1 and $doc2 or whatever.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old July 30th, 2007, 10:10 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mhkay: I TRULY appreciate the help. Hopefully this is the last question.

On the output file, I need to make it html since it will be part of a report. I want to place the values in a table cell (<td></td>) but when I use xsl:copy-of it places every value of the called out node in that cell. For instance, it has goo1.txtgoo2.txtgoo3.txt in the same cell and I'm not sure how to not get it to do that. I think that's an innate "feature" of xsl:copy-of. Thoughts?

Reply With Quote
  #6 (permalink)  
Old July 31st, 2007, 03:42 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

If you don't want a pure copy, then do a transformation, that's what XSLT is for. I'm not sure which part of the job you are finding difficult - perhaps all of it, which means I can't help you except by writing a tutorial introduction to XSLT - but they exist elsewhere. I think you need to do some reading.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple input documents pcase XSLT 2 January 8th, 2008 07:51 PM
Input with Unix files DavidD Excel VBA 3 October 17th, 2007 11:05 AM
Reading input from files PROLOG Ruman29 Other Programming Languages 0 March 8th, 2007 12:49 PM
Importing Multiple files in Multiple tables Versi Suomi Access 6 June 1st, 2005 08:47 AM



All times are GMT -4. The time now is 12:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.