如何仅当字符串值不为空时使用 xslt2.0 将字符串与“,”(逗号)分隔符连接

How to Concatenate strings with "," ( Comma ) Delimiter only when the string values are not null using xslt2.0

例如:Street, BuildingId, FloorId, UnitId 需要用 , 分隔只有当值不为空时。如果任何字段为空,请不要用逗号分隔。

 <ADDRESS nil="true"><xsl:value-of select="//street"/><xsl:text>,</xsl:text><xsl:value-of select="//buildingId"/><xsl:text>,</xsl:text><xsl:value-of select="//floorId"/><xsl:text>,</xsl:text><xsl:value-of select="//unitId"/></ADDRESS>

如果您使用的是 XSLT 2.0,请尝试:

<xsl:value-of select="(street, buildingId, floorId, unitId)[string()]" separator=","/>

演示http://xsltransform.hikmatu.com/gWmuiHS/1


已添加:

Is it possible to add a space between the attributes if any of the field is blank?

尝试:

<xsl:value-of select="for $i in (street, buildingId, floorId, unitId) return if (string($i)) then $i else ' ' " separator=","/>

演示http://xsltransform.hikmatu.com/gWmuiHS/3