如果attribute为null,则不要添加comm

时间:2015-06-10 12:55:34

标签: xslt

我有这段代码将描述一个功能名称的所有属性。如果该功能为null,它仍然会添加一个逗号。如何让代码忽略任何没有值的功能名称。

<xsl:for-each select="Feature">
  <!-- Output the feature name (there may be more than 1 feature associated -->
  <!-- with the point) so this will identify which feature the attrinbutes  -->
  <!-- are associated with.                                                 -->
  <xsl:text>,</xsl:text> <!-- Comma to separate feature name from code or previous feature -->
  <xsl:variable name="FeatName" select="@Name"/> <!-- Feature name -->
  <xsl:for-each select="Attribute">
    <xsl:if test="position() &gt;  0">
      <xsl:text>,</xsl:text> <!-- Include a comma if not first attribute -->
    </xsl:if> <!-- Prefix each attribute name with the feature it belongs to followed by a ':' -->
    <xsl:if test="$includeFieldNames = 'Yes'">
      <xsl:value-of select="concat($FeatName, ':')"/>
      <xsl:value-of select="Name"/>
      <xsl:text>,</xsl:text>
    </xsl:if>
    <xsl:value-of select="Value"/>
  </xsl:for-each>
</xsl:for-each>

1 个答案:

答案 0 :(得分:1)

  

如何让代码忽略任何没有的功能名称   值。

仅处理具有值的要素:

<xsl:for-each select="Feature[Value]">
    <!-- do your processing here -->
</xsl:for-each>