Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | 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 October 24th, 2005, 10:03 AM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default writing text file but in an order specifed...

hi there
I have two xml files and would like to generate a text file. The logic is
first.xml
<?xml version="1.0"?>
<source>
<object partid ="4" name = "def" price = "3000"/>
<object partid ="5" name = "jkl" price = "130"/>
<object partid ="1" name = "abc1" price = "0"/>
<object partid ="2" name = "def" price = "430"/>
<object partid ="3" name = "abc" price = "350"/>
<object partid ="4" name = "abc" price = "230"/>
</source>
-------------------second.xml------------------------------
<?xml version="1.0"?>
<order>
<attribute1 name= "price"/>
<attribute1 name= "name"/>
<attribute1 name= "partid"/>
</order>
__________________________________________________ ____________
Now I want to write an xslt which will output the value of each attribute of the element object but in the order as specified by the second.xml...For example in this particular case...
the output should be ...
3000, def, 4
130, jkl, 5,
etc
Any ideas/help.


Reply With Quote
  #2 (permalink)  
Old October 27th, 2005, 03:27 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:for-each select="document('first.xml')/source/object">
  <xsl:variable name="object" select="."/>
  <xsl:for-each select="document('second.xml')/order/attribute1">
    <xsl:value-of select="$object/@*[name()=current()/@name]"/>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old October 27th, 2005, 05:17 AM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael, It is working but I need to put , after every value and new line after the last value e.g.
3000, def, 4
130, jkl, 5
how to do that...Thanks in advance



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
How to import a text file w/t changing row order lxj034000 SQL Server 2000 1 July 12th, 2007 07:04 AM
Writing to Text File striker9 ASP.NET 2.0 Basics 1 May 12th, 2006 05:17 AM
problem writing dynamic value into text file in ph method PHP How-To 0 February 6th, 2006 02:05 PM
Reading from a text file and writing to a Binary 1 scott01 C++ Programming 0 July 28th, 2003 03:59 AM



All times are GMT -4. The time now is 02:08 PM.


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