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 April 12th, 2006, 01:17 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem to create an xml file from two xml files

Hi,

Please ignore my previous posting. Data was incomplete there. Following is the updated one.


I have following 2 xml files:

booklist.xml
--------------------------

  <booklist>
  <book>
  <title>C++</title>
  <author>AAAA</author>
  </book>
  <book>
  <title>XML</title>
  <author>BBBB</author>
  </book>
  <book>
  <title>Linux</title>
  <author>CCCC</author>
  </book>
  <book>
  <title>Oracle</title>
  <author>PPPP</author>
  </book>
  <book>
  <title>Java</title>
  <author>MMMM</author>
  </book>
 </booklist>

  books.xml
  -------------------
  <books>
  <book>
  <b_title>XML</b_title>
  <price>600.00</price>
  </book>
  <book>
  <b_title>C++</b_title>
  <price>300.00</price>
  </book>
  <book>
  <b_title>PHP</b_title>
  <price>500.00</price>
  </book>
  <book>
  <b_title>Python</b_title>
  <price>600.00</price>
  </book>
  <book>
  <b_title>Oracle</b_title>
  <price>1500.00</price>
  </book>


  </books>

 When the name of the title will be matched between 2 xml files
Output xml file will contain <title> from booklist.xml and <price> from
books.xml.

Output xml file will be like following:
-------------------------------------------------------------

<bookinfo>
<title>C++</title>
<price>300.00</price>
<title>XML</title>
<price>600.00</price>
<title>Oracle</title>
<price>1500.00</price>
</bookinfo>

Following xsl file I have written, but it is not working.

booklist.xsl (1st method)
------------------------------------------

  <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:variable name="btitle"
select="document('books.xml')/books/book"/>
  <xsl:template match="booklist/book">
  <bookinfo>
  <xsl:for-each select="$btitle">
  <xsl:choose>
  <xsl:when test="b_title = title">
  <title>
  <xsl:value-of select="title"/>
  </title>
  <price>
  <xsl:value-of select="$btitle/price"/>
  </price>
  </xsl:when>
  </xsl:choose>
  </xsl:for-each>
  </bookinfo>
  </xsl:template>
  </xsl:stylesheet>


  booklist.xsl (2nd method)
------------------------------------------

    <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:variable name="btitle"
select="document('books.xml')/books/book"/>
  <xsl:variable name="temp" select="document('booklist.xml')"/>
  <xsl:variable name="temp1" select="$temp/booklist/book"/>
  <xsl:template match="/">
  <bookinfo>
  <xsl:for-each select="$temp1">
  <xsl:choose>
  <xsl:when test="title = $btitle/b_title">
  <title>
  <xsl:value-of select="$temp1/title"/>
  </title>
  <price>
  <xsl:value-of select="$btitle/price"/>
  </price>
  </xsl:when>
  </xsl:choose>
  </xsl:for-each>
  </bookinfo>
  </xsl:template>

    </xsl:stylesheet>


  Any help will be highly appreciated.

  Thanks,
  Saurabh



Reply With Quote
  #2 (permalink)  
Old April 12th, 2006, 02:58 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

Please don't raise the same request simultaneously on more than one forum.

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
Create XML file - According to the Value, add elem remya1000 General .NET 0 October 2nd, 2007 11:03 PM
Create a new XML file with vbscript sswingle XML 4 April 24th, 2006 07:31 AM
Validating Xml files with XSD file ShaileshShinde VB.NET 2002/2003 Basics 1 September 12th, 2005 07:00 AM
create xml file using c# kk_katepally General .NET 2 February 11th, 2005 02:59 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM



All times are GMT -4. The time now is 12:46 PM.


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