|
|
1
5
如果您可以使用exslt,有 several date functions 可用。所有这些都是在Saxon中实现的,但是如果您使用的是MSXSL,那么ChrisBayes已经将它们实现为扩展函数,您实际上可以将其放在msxsl:script元素中的转换中。他的实现从每个特定的日期函数页链接。 是 week-in-year() 你要找的功能? 编辑: 根据Jenit的评论,有一个 pure XSLT 1.0 template 与week-in-year()功能相同的站点上可用(我认为她写的),这可能更适合您的需求。 |
|
|
2
1
如果你总是希望一周从同一天开始,那么周的计算会变得相当复杂,因为一年中的第一天总是在变化。计算它有一个ISO标准,见 this Wikipedia article . |
|
3
1
这是纯XSLT1.0解决方案 :
可以使用
这个
C:\程序文件\marrowsoft\xselerator25\samples\libraries\ 从这个库中,这里是名为“周数”的模板: <xsl:template name="week-number">
<xsl:param name="year"/>
<xsl:param name="month"/>
<xsl:param name="day"/>
<!-- or -->
<xsl:param name="date" select="''"/> <!-- format: yyyymmdd or yyyy-mm-dd -->
<!-- or -->
<xsl:param name="julian-day" select="''"/>
<!-- trim down date -->
<xsl:variable name="tdate" select="translate($date,'-','')"/>
<!-- decide which params were passed -->
<xsl:variable name="yyyy">
<xsl:choose>
<xsl:when test="string-length($date) > 0"><xsl:value-of select="substring($tdate,1,4)"/></xsl:when>
<xsl:when test="string-length($julian-day) > 0">
<xsl:variable name="jdate">
<xsl:call-template name="julian-day-to-date">
<xsl:with-param name="julian-day" select="$julian-day"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="substring($jdate,1,4)"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$year"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- get the julian day number -->
<xsl:variable name="jd">
<xsl:choose>
<xsl:when test="string-length($julian-day) > 0"><xsl:value-of select="$julian-day"/></xsl:when>
<xsl:otherwise>
<xsl:call-template name="date-to-julian-day">
<xsl:with-param name="year" select="$year"/>
<xsl:with-param name="month" select="$month"/>
<xsl:with-param name="day" select="$day"/>
<xsl:with-param name="date" select="$date"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- get the julian day number for the first working day of next year -->
<xsl:variable name="fyjd">
<xsl:call-template name="first-day-of-year">
<xsl:with-param name="year" select="$yyyy+1"/>
<xsl:with-param name="as-julian-day" select="true()"/>
</xsl:call-template>
</xsl:variable>
<!-- decide which the 'working' year for this date is -->
<xsl:variable name="start-jd">
<xsl:choose>
<xsl:when test="$jd >= $fyjd"><xsl:value-of select="$fyjd"/></xsl:when>
<xsl:otherwise>
<xsl:call-template name="date-to-julian-day">
<xsl:with-param name="date">
<xsl:call-template name="first-day-of-year">
<xsl:with-param name="year" select="$yyyy"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- final calc output -->
<xsl:value-of select="floor(($jd - $start-jd) div 7) + 1"/>
</xsl:template>
下面是一个使用“周数”模板的简单XSLT转换:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:import href=
"C:\Program Files\Marrowsoft\Xselerator25\Samples\Libraries\datetime_lib.xsl"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="week-number">
<xsl:with-param name="date" select="'2008-11-16'"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
当应用于任何源XML文档(未使用)时,将生成所需的结果: 四十六 希望这次的回答真的更有帮助。 干杯, 迪米特·诺瓦切夫。 |
|
|
4
0
查看SalMangano的XSLT食谱。有趣的是,它在 Google Books . XSLT2.0方法是:
有关1.0方式,请参见Cookbox预览。顺便说一句,我只是在网上搜索了xslt weeknumber来定位它。 |
|
|
5
-2
我用VisualBasic编程,所以我知道如何使用VB.NET。将XML日期读入变量(我们称之为 索马迪特 )然后你建立了一个新的日期, 知道 是包含未知日期的年初。那么,你就让 DATEDIFF 函数的作用是告诉您周数。
|
|
|
6
-3
在C中:
|
|
|
J_Cus504 · 在单匹配语句中使用身份变换和多谓词来沉默节点 9 月前 |
|
|
surge3333 · 使用PowerShell构建XML 9 月前 |
|
|
Sandeep · XSLT代码,用于根据条件提取元素值 11 月前 |
|
|
Reto · XSLT 3.0突发流-如何存储/获取另一个分支的值 11 月前 |
|
Ian Kemp · 如何从SelectXml调用本机XPath函数? 11 月前 |