xslt - 仅当字符串值不为空时,如何使用 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
添加:
如果任何字段为空白,是否可以在属性之间添加空格?
尝试:
<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
推荐阅读
- python - 如何查找网络 ID
- tsql - 我有一个要求,我需要在 Azure SQL DW 中将列值动态转换为列标题
- python - 遵循 python googl-style-guide 时避免使用静态成员和方法
- python-3.x - 在 CPLEX 上实施软规则
- linux - Ubuntu / NGINX - 无法更改某些目录和文件的所有权或权限
- swift - 将数据从蓝牙设备转换为可读字符串
- python - 比较具有相同形状但沿轴移动的两条曲线
- java - JVM 搜索 install4j 应用程序的回退
- ssl - 将 Http 更改为 Https 用于 c# Web 应用程序
- media-player - UNO 中对 Web Assembly 的媒体播放器支持