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 .

To form a ASP.NET dropdownlist I transformed the XML from elements to attributes and reduced it to just the four elements that are relevant to the assignment and saves it as another XML file. The dropdownlist includes hotelId as SelectedValue and name as SelectedItem. When an item is selected it has already retuned the selectedValue. With that said, my challenges are to assure that the new XML file was transformed correctly so it can be input into a .NET dataset where query can be run against it to return data based on hotelId from the dropdown SelectedValue content. Can you help me with this transformation to extract four elements out of a xml file that has multiple elements including one element RateInfo which has some child elements and some attributes. The template also need to have a key, hotelId. The RateInfo can be transformed to output with attributes separated by a comma.

I don't think you'll find you'll get any different answers here than you will on the dedicated XSLT forum.

The main problem with what you are asking is that you do no tell us what you want you output XML to look like. With an example input and an example output we can help you write an XSLT stylesheet which will perform the transformation from one to the other. Without one or the other we would be left making huge guesses, which we really have better things to do.

Also you talk about multiple hotels, but your XML above only contains 1 hotel, therefore there is probably some XML you are not showing us.

And you keep using various words that we're not sure mean what we usually take them to mean. For example in XSLT the word 'template' has a very specific meaning - its a section of an XSLT transformation that handles a particular function or element. Likewise when you refer to 'attribute' are you talking about an XML attribute, or do you really mean element?

My apologies for not providing a output due to my lack of XSL knowledge. Here is the complete xml file followed by the output. Input test xml file has five hotels but the requirment demands the solution to be scalable. Feel free to ask for further clarification if need be. Thanks.

You really aren't making life easy for people who want to help you. Switching to a new thread on a different forum is like saying the same think louder when people say they don't understand you.

Producing your example output is easy. But I can't see how it relates to your description of the problem. The output doesn't include any attributes, let alone attributes separated by a comma, and being XML rather than HTML, I can't see where the drop-down list comes into it.

You essentially want two template rules, one for elements that need to be copied:

Since most of the elements are to be deleted, I would make the second rule the default one (match="*") and in the first rule, list the elements you want to retain: match="Hotel | hotelId | name | shortDescription | RateInfo | RateInfo/*"

My apologies if switching thread caused any inconvenience. I switched out of dyer desperation. As far as the transformation, Michael is correct in stating that I failed to provide the output in the attribute format as I mentioned previously. So I modified it but I did not put those comma delimeters inside the RateInfo attribute for I was not sure whether literal ","'s are acceptable. Nor did I do any format change with Displaynightlyrate and Nativenightlyrate. I put other attributes in that are address related thinking that the requirement might mean to include. So here it is the attribute format output the best way I can depict it.

Why would you want to produce output in a format that has many similarities with XML, but is not XML? What do you intend to do with this output? What can you do with it that you couldn't do with the original XML?

All I need to do is two things:
1. to populate the dropdownlist so user can select the hotel from the list.

2. to populate the key info of the hotel selected into a Label control so it will be displayed on the page upon selectionchanged event.

I first used attributes because I saw a sample code that use XML attributes to populate a dropdown so I thought I had to first convert elements to attributes. And now I already identified that .NET linq has access to XML.attribute(attributename) so I can accomplish populating Label control using attributes. So my understanding now is that I just need one XSL transformation to convert elements to attributes and that should take care of both parts 1 and 2. As I mentioned that I had not much XML/XSLT experience so I am not sure if there is one way to do what I need to do with the original XML. And it makes sense for me to convert to attributes for it sounds like a resolution. I am sure there may be other solutions but I just need a solution ASAP.

I think you need to do a lot more reading before you do any more coding. You haven't grasped the key concepts about the architecture of the application you are building. You don't need to generate attributes, and you don't even seem to know what attributes are.

Your difficulty is that you haven't got it clear in your head what output you want your stylesheet to produce. As Dijkstra once said, you should never start writing a program until you understand what output it should produce. You need to generate HTML from your XML.

I would start by hand-crafting the HTML that you want to produce, and checking that this HTML works as expected in the browser. Then that defines the target of your transformation. If you don't know how to write the HTML, then you need to learn some HTML. Once you have worked out what HTML you need to produce, come back here and ask questions about how to produce it.

I am trying to learn XSLT and had just found out that like you pointed out that the whole thing can be done easily in XML/XSLT. But the people have me do this wants from me both a XSL file and a ASP.NET file so I take it they want to use ASP.NET controls vs. HTML. With that said do you think it does make sense to convert to attributes? What is your take? Thanks.