Justin Mock
Justin Mock

Reputation: 55

Is it possible to make a selectable drop down menu using data from an XML file?

I'm trying to create a directory for an address book, and I was wondering if it would be possible to create a selectable drop down menu that would pull the contact data from an XML file. The ideal way I would want it is to have all of the names of the contacts in the drop down menu, and when one is selected the rest of the information would pop up above the drop down, such as Address, Phone Number, and Email.

Upvotes: 0

Views: 238

Answers (3)

Jonathon Ashworth
Jonathon Ashworth

Reputation: 1114

Either use a server-side language such as PHP to extract the data from the XML and insert it into the HTML document, or use AJAX to pull the XML file to the client then use JavaScript to process it and insert it into the DOM.

There should be libraries/frameworks/plugins/whatever available to parse XML using whatever language you need, if you know how to insert stuff into the HTML document (in the case of PHP) or into the DOM (in the case of JavaScript), you can do this easy.

Upvotes: 1

Sbof
Sbof

Reputation: 51

You could attach an XSL to the XML using something like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
... actual XML content...

If applying the XSL on the XML outputs an HTML page with JavaScript, you can get the actual result. Outputting JavaScript is a bit of a pain because of character escaping but it can be done.

Upvotes: 0

Peter
Peter

Reputation: 1796

From what I understand you have an XML document. Using XSLT you create an XHTML file from your XML and that you can display in your browser (XHTML is HTML that is conform to XML rules).

If that is the case then, yes, you can make links using XSLT. But the data needs to be in your XML source file and not in some database.

There is an article that describes it: http://www.ibm.com/developerworks/xml/library/x-tipxslt/index.html

Upvotes: 0

Related Questions