Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 November 17th, 2008, 03:29 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transfer one xml to another

Now I have two xml file. I would like transfer the first XML to the second XML.

The difference between these two xml files is: the above xml is to just list book information, like its first author, 2rd author, book name, etc. The second xml is a result XML file grouped by first author, author1.

The below xml has an attribute, "Author". All books, whose first author is "Mike", in the above xml is grouped into one block in the below xml; all books, whose first author is "Nancy", is gouped into another block in the below xml; ....

How can I use XSLT to complete it? Thanks a lot.

First xml :

<BookStore>
  <Books>
    <Book>
      <BookAuthors>
        <Author1>Mike</Author1>
        <Author2>Tome</Author2>
        <Author3>Jane</Author3>
      </BookAuthors>
      <BookName>BookName1</BookName>
      <BookType>Math</BookType>
    </Book>
    <Book>
      <BookAuthors>
        <Author1>Mike</Author1>
        <Author2>Gary</Author2>
        <Author3>Henry</Author3>
      </BookAuthors>
      <BookName>BookName2</BookName>
      <BookType>Physics</BookType>
    </Book>
    <Book>
      <BookAuthors>
        <Author1>Nancy</Author1>
      </BookAuthors>
      <BookName>BookName2</BookName>
      <BookType>Physics</BookType>
    </Book>
   </Books>
</BookStore>


Second xml:
<BookStore>
  <BookFirstAuthor FirstAuthor="Mike">
    <Book>
      <BookAuthors>
        <Author1>Mike</Author1>
        <Author2>Tome</Author2>
        <Author3>Jane</Author3>
      </BookAuthors>
      <BookName>BookName1</BookName>
      <BookType>Math</BookType>
    </Book>
    <Book>
      <BookAuthors>
        <Author1>Mike</Author1>
        <Author2>Gary</Author2>
        <Author3>Henry</Author3>
      </BookAuthors>
      <BookName>BookName2</BookName>
      <BookType>Physics</BookType>
    </Book>
  </BookFirstAuthor>

  <BookFirstAuthor FirstAuthor="Nancy">
   <Book>
      <BookAuthors>
        <Author1>Nancy</Author1>
      </BookAuthors>
      <BookName>BookName3</BookName>
      <BookType>Physics</BookType>
    </Book>
  </BookFirstAuthor>
 </BookStore>
 
Old November 17th, 2008, 11:24 PM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try this:

<xsl:template match="Books">
        <BookStore>
            <xsl:for-each-group select="Book" group-by=".//Author1">
                <BookFirstAuthor FirstAuthor="{.//Author1}">
                <xsl:copy-of select="current-group()"></xsl:copy-of>
                </BookFirstAuthor>
            </xsl:for-each-group>
        </BookStore>
    </xsl:template>

------
Rummy




Similar Threads
Thread Thread Starter Forum Replies Last Post
server.transfer and XML spinout ASP.NET 1.0 and 1.1 Basics 1 March 26th, 2008 08:21 AM
DATA TRANSFER vish_vj ADO.NET 1 March 7th, 2008 01:16 PM
BLOB transfer koushal SharePoint Development 0 July 17th, 2007 06:54 PM
transfer xml file to specified location using soap rjkulkarni2001 .NET Web Services 0 April 4th, 2006 08:13 AM
Using Internet Transfer Control to post XML jaforret Classic ASP XML 2 February 29th, 2004 02:43 PM





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