将 IF 子句添加到 XSL 调用模板

Adding a IF clause to XSL call-template

我是 XSL 的新手,正在尝试编辑其他人的代码。

xsl 调用一个模板 "formatAustralianDate" 并且 return 是一个数字。但是,如果@created 为空,则 returns NaN 天

 <xsl:call-template name="formatAustralianDate">
          <xsl:with-param name="dateValue" select="@Created"/>
 </xsl:call-template> day(s)

有什么方法可以测试@Created 是否为空(或空白),如果是,那么只有 return 0 天?甚至更好,空白

XSLT 有点生疏,但可能类似于:

<xsl:if test="floor(@Created)>0">
 <!-- code here if test passes -->
</xsl:if>

你可以在这里使用 xsl:choose

<xsl:choose>
   <xsl:when test="normalize-space(@created)">
      <xsl:call-template name="formatAustralianDate">
         <xsl:with-param name="dateValue" select="@created"/>
      </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
       <xsl:text>0</xsl:text>
   </xsl:otherwise>
</xsl:choose>
<xsl:text> day(s)</xsl:text>

如果created不存在,或者是一个空字符串(或者是一个white-space only-string,normalize-space然后转换为一个空字符串) ,然后测试 returns 为假,而 xsl:otherwise 被评估。