Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: XSLT Programmer's Reference, 2nd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: XSLT Programmer's Reference, 2nd Edition
This is the forum to discuss the Wrox book XSLT: Programmer's Reference, 2nd Edition by Michael Kay; ISBN: 9780764543814
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT Programmer's Reference, 2nd Edition 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
Closed Thread
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 30th, 2011, 05:44 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting xml info from another xml stracture via xslt

I'm using XSLT 1.0 and I'm tring to make the follwing thing :

I've got a 1.xml file :

<root>
<elem1>value1</elem1>
<elem2>
<elem3>
<param1>value2</param1>
<param2>value3</param2>
</elem3>
</elem2>
<elem4>
<param3>value4</param3>
</elem4>
</root>

Now a client passes me another xml file that tells me what elements he wants me to give him back (could change between clients), i.e. :

<root>
<RequiredElements>
<elementName>elem1</elementName>
<elementName>elem2/elem3/param1</elementName>
</RequiredElements>
</root>

Which means that in this case, I should make another xml file, with this stracture:

<root>
<elem1>value1</elem1>
<elem2>
<elem3>
<param1>value2</param1>
</elem3>
</elem2>
</root>

I've tried to come up with something in xslt (no programing languages other than that) to get the stracture that I need, but couldn't make it.

Any ideas or pointers of what should I do?

Thanks for the help.
  #2 (permalink)  
Old October 30th, 2011, 04:36 PM
mhkay's Avatar
Wrox Author
Points: 17,773, Level: 58
Points: 17,773, Level: 58 Points: 17,773, Level: 58 Points: 17,773, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,839
Thanks: 0
Thanked 267 Times in 262 Posts
Default

You haven't actually explained the format of the output you want back, so I can't give you detailed code. But I would tackle the problem by writing a stylesheet that takes the "RequiredElements" document as input, and generates an XSLT stylesheet as output; and then run this generated stylesheet against your original XML document. This kind of approach is very often the best way of dealing with problems where an XML document acts as a specification of required processing.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Closed Thread


Thread Tools
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
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 12:23 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 05:01 PM



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


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