从生日计算xslt的年龄 [英] calculate age in xslt from birthday

查看:181
本文介绍了从生日计算xslt的年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量加注生日,其值将如$ code> 1/1/1970 。我需要根据该值计算一个人的年龄。基本上是从 birthday 变量的 currentdate() - 年的一年。但是如何在XSLT中实现?它与Sharepoint DateView webpart有关。 日期时间的字段生日。我需要使用该字段提取年龄。任何人都可以指向正确的方向?

I have a variable caled Birthday which will have value like 1/1/1970. I need to calculate the age of a person based on that value. It would basically be the year from currentdate()-year from the Birthday variable. But How do I achieve this in XSLT? It is related to sharepoint DateView webpart. There is a field Birthday of datetime type. I need to extract age using that field. Can anyone point me in the right direction?

推荐答案

<xsl:variable name="Age">
    <xsl:choose>
        <xsl:when test="month-from-date(current-date()) > month-from-date($Birthday) or month-from-date(current-date()) = month-from-date($Birthday) and day-from-date(current-date()) >= day-from-date($Birthday)">
            <xsl:value-of select="year-from-date(current-date()) - year-from-date($Birthday)" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="year-from-date(current-date()) - year-from-date($Birthday) - 1" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

这篇关于从生日计算xslt的年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆