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 April 21st, 2006, 02:57 PM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Saving in multiple files at the same time

Hello,

  Imagine I have the following XML input:

<doc>
 <entry>
  <a>some data</a>
  <b>some data</b>
 </entry>
 <entry>
  <a>more data</a>
  <b>more data</b>
 </entry>
</doc>

  And I want to produce something like this in the output

FILE 1:
<group_a>
 <a>some data</a>
 <a>more data</a>
</group_a>

FILE 2:
<group_b>
 <b>some data</b>
 <b>more data</b>
</group_b>

  I know how to do this kind of transformation in two passes. But can it be done in one pass? I have a really big XML file, and I'd sure like to avoid iterating through its elements multiple times. In other words, can I handle multiple files in the output simultaneously? If so, how?

  Thanks in advance,
   Rodrigo

 
Old April 21st, 2006, 03:07 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can do this in XSLT 2.0 using the xsl:result-document instruction.

You can't do it in standard XSLT 1.0, but several XSLT 1.0 processors provide an extension instruction for the purpose.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 24th, 2006, 07:01 AM
Registered User
 
Join Date: Apr 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I know about the result-document statement, but I don't know how to use it to do the transformation in a single pass. What I meant from my previous question was that, if a had to separate my XML input in ten different files, I'd have to write ten "for" statements, one for each class I had in mind, generating one file at a time. What I'd like to have is some way to build multiple files at the same time; for instance, while iterating through the many elements, test "if this element is of the type A, it goes into file A.xml; if it is of type B, it goes into B.xml..." and so on.

 
Old April 24th, 2006, 07:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

xsl:result-document doesn't work that way. The reason is that the order of items in the output files would then depend on the order of evaluation of instructions in the "loop" (which isn't really a loop at all, it's a mapping function). Writing documents is thus just like writing multiple elements: you have to structure your code according to the output you are producing, not the input you are 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
Importing Multiple files in Multiple tables Versi Suomi Access 6 June 1st, 2005 08:47 AM
Saving Files on the Client System BSkelding ASP.NET 1.0 and 1.1 Basics 5 March 25th, 2004 01:25 PM
saving files using jscript shine Javascript How-To 2 January 2nd, 2004 11:56 AM
Uploading Multiple Files at a time to Server tapan_acharya .NET Web Services 0 July 17th, 2003 07:55 AM





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