p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: XSLT Programmer's Reference, 2nd Edition (http://p2p.wrox.com/book-xslt-programmers-reference-2nd-edition-52/)
-   -   Getting xml info from another xml stracture via xslt (http://p2p.wrox.com/book-xslt-programmers-reference-2nd-edition/85518-getting-xml-info-another-xml-stracture-via-xslt.html)

iidev October 30th, 2011 05:44 AM

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.

mhkay October 30th, 2011 04:36 PM

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.


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

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