I am new to XSLT. I am trying to parse the result in XML 1.0 and generate:
Keyword A,Keyword B,Keyword C,Keyword D
but the separator is not shown. I just got the result
Keyword A Keyword B Keyword C Keyword D
My XML and XSLT code are as below:
Product.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="style.xsl" ?>
<products>
<product id="1" name="My Product">
<keywords>
<keyword>
Keyword A
</keyword>
<keyword>
Keyword B
</keyword>
<keyword>
Keyword C
</keyword>
<keyword>
Keyword D
</keyword>
</keywords>
</product>
</products>
style.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="products/product">
<xsl:for-each select="keywords">
<xsl:choose>
<xsl:when test="position()=last()">
<xsl:value-of select="current()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="current()"/>
<xsl:text>,</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I have already look at if-else statement in XSLT but I cannot find the answer.