• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

dynamic xml output based on user input

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Ranjit
-------------------------------------------------------------------------
the Employee.xml is this

<EMPLOYEEDETAILS>
<EMPLOYEE>
<ID number="no">1</ID>
<NAME>
<FIRSTNAME>JOHN</FIRSTNAME>
<LASTNAME>PAUL</LASTNAME>
</NAME>
<AGE>21</AGE>
<SEX>MALE</SEX>
<DATEOFBIRTH>28/07/1985</DATEOFBIRTH>
<DATEOFJOINING>20/10/2004</DATEOFJOINING>
<ADDRESS>
<RESIDENTIAL>PETERS ROAD</RESIDENTIAL>
<OFFICE>SSSC</OFFICE>
</ADDRESS>
<CONTACTDETAILS>
<PHONENUMBER>
<MOBILE>985268587</MOBILE>
<LANDLINE>5789472</LANDLINE>
</PHONENUMBER>
<EMAIL>MAILTOME@CA.COM</EMAIL>
</CONTACTDETAILS>
</EMPLOYEE>
<EMPLOYEE>...</EMPLOYEE></EMPLOYEEDETAILS>



-----------------------------------------------------------------



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:variable name="testvalue">2</xsl:variable>

<xsl:template match="/">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE><xsl:value-of select="EMPLOYEEDETAILS/TITLE" /></TITLE>
</HEAD>
<script>
function showEmployee(sI){
alert(sI);
}
</script>
<BODY>

<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:for-each>
</xsl:element>


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

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

<!--********************************************************************************
**"EMPLOYEE" template
************************************************************************************-->
<xsl:template match="EMPLOYEE">
<TABLE ALIGN="CENTER" BORDER="1">
<TR>
<TD>Employee ID</TD>
<TD>First Name</TD>
<TD>Last Name</TD>
<TD>Age</TD>
<TD>Sex</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>
</TR>
<TR>
<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/PHONENUMBER/MOBILE"/></TD>
<TD><xsl:value-of select="CONTACTDETAILS/PHONENUMBER/LANDLINE"/></TD>
<TD><xsl:value-of select="CONTACTDETAILS/EMAIL"/></TD>
</TR>
</TABLE>
</xsl:template>


</xsl:stylesheet>
 
Ranjit Gopinath
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And yeah..i am not looking for a java solution...

thanks again

rg
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Bill
 
Ranjit Gopinath
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you William. Got the idea.

-Ranjit
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!