简体   繁体   English

向XSL调用模板添加IF子句

[英]Adding a IF clause to XSL call-template

I'm very new to XSL and am trying to edit someone elses code. 我是XSL的新手,正在尝试编辑其他人的代码。

The xsl calls a template "formatAustralianDate" and returns a number. xsl调用模板“ formatAustralianDate”并返回数字。 However, if @created is null it returns NaN days 但是,如果@created为null,则返回NaN天

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

is there a way I can test if @Created is null (or blank) and if it is, then just return 0 days? 有没有一种方法可以测试@Created是否为null(或空白),是否可以返回0天? or even better, blank 甚至更好,空白

You could use an xsl:choose here 您可以在此处使用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>

If created does not exist, or is an empty string (or is a white-space only-string, which normalize-space then converts to an empty string), then the test returns false, and the xsl:otherwise is evaluated instead. 如果created不存在,或者为空字符串(或为仅空白字符串,然后将规范化空间转换为空字符串),则测试返回false,然后对xsl:otherwise进行评估。

Bit rusty on XSLT but perhaps something along the lines of: 对XSLT有点生疏,但也许符合以下方面:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM