I am trying to write an XSL for an XML to output another XML.
The input XML looks like this:
I need to convert this to the following output:
I need to know a couple of things.
1. how can I write xpath that loops through elements of Info/Address 2. How can I select the name of the element from the input xml and represent it as value in the output xml? 3. how can I use string functions to produce <data name="BillingAddressInfo">? [concat address+info]
Originally posted by Vrinda Werdel: 1. how can I write xpath that loops through elements of Info/Address
Well, the XPath expression "Info/Address" does give you a list of the elements you want. But it doesn't "loop through" them, it just is a list. Actually you should stop thinking of looping through things in XSLT and XPath, as that will lead you to write ugly code. It's better to accept XSLT for the functional language that it is and not try to write procedural code as if it were strangely-formatted Java. In other words, write templates that transform particular elements in the way you want them transformed.
You should be able to find examples of that style of XSLT programming in any basic book or tutorial about the language.
2. How can I select the name of the element from the input xml and represent it as value in the output xml?
That would be the name() or local-name() XPath function. And you can use an xsl-element element to create an element with a name that you don't know, like this:However in your case you already know the name of the element you want to create, so I would simply write an ordinary XML element with that name.
3. how can I use string functions to produce <data name="BillingAddressInfo">? [concat address+info]
But all these questions you are asking suggest to me that you have never read a book or even a tutorial about XSLT. You won't find it easy to learn a programming language by asking questions on a forum. I suggest you should get yourself a reference and start reading.
Roseanne Zhang
Ranch Hand
Joined: Nov 14, 2000
Posts: 1953
posted
0
Here is an answer based on your question, but not exact.