my dog learned polymorphism
The moose likes XML and Related Technologies and the fly likes dynamic xml output based on user input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "dynamic xml output based on user input" Watch "dynamic xml output based on user input" New topic

dynamic xml output based on user input

Ranjit Gopinath

Joined: Aug 30, 2006
Posts: 7
This is what i am trying to do...

1. There is an xml Employee.xml which contains the information of employees.
2. I have created an xsl file which takes takes this xml and outputs an html file with a drop down list of Employee ID's..

Now my question is, is it possible to display the details of the employee an user has selected the same page dynamically.By dynamically i mean, the details of the employee should change based on the user selection. I have done it using javascript, but is it possible using xsl??

I have tried many times and failed miserably..
Hope someone can help me with a hint,or a snippet or a link...

Thanks in advance.

the Employee.xml is this

<ID number="no">1</ID>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xslutput method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system=""/>
<xsl:variable name="testvalue">2</xsl:variable>

<xsl:template match="/">
<HTML xmlns="">
<TITLE><xsl:value-of select="EMPLOYEEDETAILS/TITLE" /></TITLE>
function showEmployee(sI){

<xsl:element name="select">
<xsl:attribute name="name">employeeName</xsl:attribute>
<xsl:attribute name="onChange">showEmployee(this.selectedIndex)</xsl:attribute>
<option value="top">-Select-</option>
<xsl:for-each select="/EMPLOYEEDETAILS/EMPLOYEE">
<xsl:attribute name="id"><xsl:value-of select="ID" /></xsl:attribute>
<xsl:text disable-output-escaping="yes"><</xsl:text>option value="<xsl:value-of select="ID" />"<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:value-of select="ID" />

<xsl:value-of select="EMPLOYEEDETAILS/TITLE" />

<xsl:apply-templates select="EMPLOYEEDETAILS/EMPLOYEE[ID='1']"/>

**"EMPLOYEE" template
<xsl:template match="EMPLOYEE">
<TD>Employee ID</TD>
<TD>First Name</TD>
<TD>Last Name</TD>
<TD>Date of Birth</TD>
<TD>Date of Joining</TD>
<TD>Residence Address</TD>
<TD>Official Address</TD>
<TD>Mobile No:</TD>
<TD>Landline No:</TD>
<TD>Email Id</TD>
<TD><xsl:value-of select="ID"/></TD>
<TD><xsl:value-of select="NAME/FIRSTNAME"/></TD>
<TD><xsl:value-of select="NAME/LASTNAME"/></TD>
<TD><xsl:value-of select="AGE"/></TD>
<TD><xsl:value-of select="SEX"/></TD>
<TD><xsl:value-of select="DATEOFBIRTH"/></TD>
<TD><xsl:value-of select="DATEOFJOINING"/></TD>
<TD><xsl:value-of select="ADDRESS/RESIDENTIAL"/></TD>
<TD><xsl:value-of select="ADDRESS/OFFICE"/></TD>
<TD><xsl:value-of select="CONTACTDETAILS/EMAIL"/></TD>

Ranjit Gopinath

Joined: Aug 30, 2006
Posts: 7
And yeah..i am not looking for a java solution...

thanks again

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
but is it possible using xsl??

I think you are looking at this the wrong way, XSL is just formatting a HTML page for you. The real question is can HTML be formatted so that the page behaves the way you want.

It is possible to write an HTML page containing all the possible information but with most of it hidden - to be revealed by Javascript actions caused by user events. So the real question is can you write the HTML page (including Javascript) using XSLT - of course you can.

Ranjit Gopinath

Joined: Aug 30, 2006
Posts: 7
Thank you William. Got the idea.

I agree. Here's the link:
subject: dynamic xml output based on user input
It's not a secret anymore!