Reputation: 37
I'm new to XSLT & XML. I need to get the value of xml node to send it to the Javascript. I tried to put the value into a variable and send the variable via onclick event. I'm pretty sure Im doing something fishy on passing variable. Please help me figure out what I'm doing wrong here!
<xsl:for-each select="itemCart/items">
<xsl:if test="iQty>0">
<tr>
<xsl:variable name="myId" select="@iId" />
<td><xsl:value-of select="iId"/></td>
<td><xsl:value-of select="iName"/></td>
<td><xsl:value-of select="iPrice"/></td>
<td><xsl:value-of select="iQty"/></td>
<td><xsl:value-of select="iDesc"/></td>
<td><button type="button" onclick="addItem('myId')" >Add one to cart</button></td>
</tr>
</xsl:if>
</xsl:for-each>
1. When I alert it it outputs myId
2. Without quotations it doesn't alert at all
Upvotes: 2
Views: 5589
Reputation: 56162
Use brackets and $
sign to access variable, i.e.:
<button type="button" onclick="addItem('{$myId}')">Add one to cart</button>
Upvotes: 2