xslt - Use buttons to update XML element styled with XSL -


as newbie xsl, minimal exposure xml, i'm having trouble figuring out how integrate 2 html. i'd use 2 buttons update 2 elements captured in xml document , have update elements displayed using xsl stylesheet. i've provided snippets of code below.

xml

<best_answer> <head>    <title>title text goes here </title>   <objective>      <goal>goal text goes here</goal>   </objective>    <settings>        <setting type="application">app name</setting>   </settings>  <verifications>    <verification type="helpful">10</verification>    <verification type="unhelpful">5</verification> </verifications>  </head> </best_answer> 

xsl

  <xsl:template match="verifications">   <br></br>   <table style="border:1px dashed; align: center; border-spacing: 5px; width: 100%">  <tr colspan="2">    <td >was topic helpful?</td>  </tr>   <tr>    <td style="padding-left:20px;">      <button id="yes" type="button">yes</button>    </td>     <td style="padding-left:30px;">      <button id="no" type="button">no</button>    </td>  </tr>   <tr></tr>  <tr></tr>   <tr>    <xsl:for-each select="verification">      <xsl:choose>        <xsl:when test="@type='helpful'">          <td>            <img src="image.png" height="12" width="16">            </img>             &#160;<xsl:value-of select="@type"/>:             <xsl:value-of select="text()"/><xsl:text></xsl:text>           </td>        </xsl:when>        <xsl:otherwise>          <img src="image2.png" height="12" width="16">          </img>          &#160;<xsl:value-of select="@type"/>:           <xsl:value-of select="text()"/><xsl:text></xsl:text>         </xsl:otherwise>      </xsl:choose>                       </xsl:for-each>    </tr> </table>  </xsl:template> 

i'd have "yes" button update verification text type equals "helpful" , have "no" button update verification text type equals "unhelpful". example, if user clicks "yes" button, text captured in verification element type "helpful" should increment one. likewise, if user clicks "no" button, text captured in verification element type of "unhelpful" should increment one.

hope makes sense...any can provided appreciated. thanks!

here's use starting point:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:template match="/best_answer">     <html>         <head>             <script>                 function incrementvalue(id)                 {                     var element = document.getelementbyid(id);                     element.innerhtml = parseint(element.innerhtml) + 1                 }             </script>         </head>         <body>             <table border="1">                <tr>                   <td colspan="2">was topic helpful?</td>                </tr>                <tr>                   <td>                      <button onclick="incrementvalue('positive')">yes</button>                   </td>                   <td>                      <button onclick="incrementvalue('negative')">no</button>                   </td>                </tr>                <tr>                   <td>helpful</td>                   <td>unhelpful</td>                </tr>                 <tr>                     <td id="positive">                         <xsl:value-of select="head/verifications/verification[@type='helpful']"/>                     </td>                     <td id="negative">                         <xsl:value-of select="head/verifications/verification[@type='unhelpful']"/>                     </td>                 </tr>             </table>         </body>     </html> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -