Click here to Skip to main content
15,891,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
i have created a table using HTML, XML and XLST. the I am creating a table using a for-each loop which inserts the data from the xml file.
Once the table is filled with data, i would like every cell that is clicked to display dialogue message box.

Code for XML file:

    <person>
        <title>Abraham</title>
        <slota>Johns</slota>
        <slotb>22</slotb>
        <slotc>male</slotc>
        <slotd>ave road</slotd>
        <slote>0384847</slote>
        <slotf>shdh@hot.com</slotf>
        <slotg>UK</slotg>
      </person>

Above is the code with all the data needed to be inserted into the table.

XLST Code:

    <table border="1" cellspacing="0">
            <tr>
              <th bgcolor="DarkGray" >Employee</th>
              <th id="cell1" bgcolor="DarkGray">name</th>
              <th id="cell2" bgcolor="DarkGray">surname</th>
               <th id="cell3" bgcolor="DarkGray">age</th>
              <th id="cell4" bgcolor="DarkGray">gender</th>
              <th id="cell5" bgcolor="DarkGray">address</th>
               <th id="cell6" bgcolor="DarkGray">phone</th>
              <th  id="cell7" bgcolor="DarkGray">country</th>

            </tr>
            <xsl:for-each select="persons">
            <tr>
               <td><xsl:value-of select="title" /></td>
               <td><xsl:value-of select="slota" /></td>
               <td><xsl:value-of select="slotb" /></td>
               <td><xsl:value-of select="slotc" /></td>
               <td><xsl:value-of select="slotd" /></td>
                td><xsl:value-of select="slote" /></td>
               <td><xsl:value-of select="slotf" /></td>
           <td><xsl:value-of select="slotg" /></td>
             </tr>
            </xsl:for-each>
          </table>

Above is the code for xsl file creating the table and inserting data using the for-each loop.

I have created a function that displays a dialog message box using java script and here the code below:

    <script>
        function myFunction()
        {

          alert ("I am an alert box");
          }
          </script>

when i place this function in a table cell that i would it to be triggers it for example:

    <td onclick="myFunction()"><xsl:value-of select="slota" /></td>.


The function applies to each and every table cell in that row.

Is there a way i can apply this function to one specific cell?
or is because i am using a for-each  loop to create the tabel?

I hope this makes sense..

and thank you in advance.
Posted

1 solution

Ensure you have defined the full HTML output declaration in your XSLT file (<xsl:output... xmlns:xsl="#unknown">) then add in the javascript code (With tags) after the html markup in your XSLT.
Add the onclick javascript handlers to the td tags in your XSLT.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900