You can specifiy a condition for an action with xsl:if
The condition is an XPath contained in a 'test' attribute.
There is no "else" part.
Example:
<xsl:template match="namelist/name"> <xsl:apply-templates/> <xsl:if test="preceding-sibling::*">, </xsl:if> </xsl:template>