Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 30th, 2007, 12:04 PM
Registered User
 
Join Date: Jul 2007
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.

 
Old July 30th, 2007, 03:30 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old July 30th, 2007, 04:36 PM
Registered User
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how would I accomplish this WITH the document()?

 
Old July 30th, 2007, 05:02 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old July 30th, 2007, 10:10 PM
Registered User
 
Join Date: Jul 2007
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?

 
Old July 31st, 2007, 03:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.