2013-05-07 95 views
3

我想用提取毫秒以下XPATH:忽略來自日期

<xsl:template match="//alarms:alarmRaisedTime"> 
     <xsl:variable name="secondsSince1970" select="(xs:dateTime(.) - xs:dateTime('1970-01-01T00:00:00')) div xs:dayTimeDuration('PT1S')" /> 
     <xsl:element name="alarmRaisedTime" namespace="MY NAME SPACE"> 
      <xsl:value-of select="$secondsSince1970"/> 
     </xsl:element> 
</xsl:template> 

輸出我得到的是

<alarmRaisedTime>1367855105.001</alarmRaisedTime> 

我希望得到如下輸出(注意毫秒的是移除)

<alarmRaisedTime>1367855105</alarmRaisedTime> 

我嘗試以下:

<xsl:value-of select="fn:substring-before($secondsSince1970,.)"/> 

但它沒有工作。

回答

1

嘗試

<xsl:value-of select="fn:substring-before($secondsSince1970,'.')"/> 

在你表達的.指上下文項目alarms:alarmsRaisedTime

2

更簡單

floor($secondsSince1970) 

通過definition

floor函數返回不大於參數並且是整數的最大(最接近正無窮大)數字。