首页 > 解决方案 > 仅当字符串值不为空时,如何使用 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>

标签: xsltconcatenationcommanotnull

解决方案


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

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

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


添加:

如果任何字段为空白,是否可以在属性之间添加空格?

尝试:

<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


推荐阅读