'How to insert the value-of-select name into the href link?
I would like to pass the name into the link so that when i clicked the button the name will passed in. Any suggestion for how to edit the button?
<xsl:for-each select="person">
<tr>
<td><xsl:value-of select="position()"/>.</td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="date"/></td>
<td><xsl:value-of select="contact"/></td>
<td><xsl:value-of select="email"/></td>
<td><xsl:value-of select="address"/></td>
<td>
<a href="updateMember.php?name=" class="btn-secondary">Update Member</a>
<a href="deleteMember.php?name=" class="btn-danger">Delete Member</a>
</td>
</tr>
</xsl:for-each>
Solution 1:[1]
You can use {expression} to include an Xpath expression in a string context.
Variables can be defined with xsl:variable.
EXSLT can be used for advanced features. One of them is str:encode-uri(). You define the additional namespace on the xsl:stylesheet element and set it as an extension element prefix.
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str">
<xsl:template name="example">
<xsl:for-each select="person">
<xsl:variable name="encodedName" select="str:encode-uri(name)"/>
<tr>
<td>
<a href="updateMember.php?name={$encodedName}" class="btn-secondary">Update Member</a>
<a href="deleteMember.php?name={$encodedName}" class="btn-danger">Delete Member</a>
</td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Solution 2:[2]
If you are talking about the name you output earlier with <td><xsl:value-of select="name"/></td> then using a href="updateMember.php?name={$name}" should do, although depending on your data you might need to escape the value of name in the URL, easily done in XPath/XSLT 3 with {encode-for-uri($name)}, I don't think XSLT/XPath 1.0 has a function for that, unless you call e.g. into PHP from XSLT.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ThW |
| Solution 2 | Martin Honnen |
