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 October 24th, 2005, 10:03 AM
Registered User
 
Join Date: Oct 2005
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.


 
Old October 27th, 2005, 03:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old October 27th, 2005, 05:17 AM
Registered User
 
Join Date: Oct 2005
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








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





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