这是我的开始XML:
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Sick</leaveDescription>
<leaveCodeStr>SS</leaveCodeStr>
<balanceAmount>90.22</balanceAmount>
<leaveDescription>Vacation</leaveDescription>
<leaveCodeStr>VA</leaveCodeStr>
<balanceAmount>187.11</balanceAmount>
<leaveDescription>Winter Recess</leaveDescription>
<leaveCodeStr>WR</leaveCodeStr>
<balanceAmount>30</balanceAmount>
<effectiveDate>03/11/2013 23:59:59</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>03/11/2013 23:59:59</lastPayEndDate>
</leaveBalanceTotal>
我正在使用此XSLT将其转换为我需要的格式:
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xtt="urn:com.workday/xtt"
xmlns:etv="urn:com.workday/etv"
xmlns:wd="urn:com.workday.report/CR-INT486-Kuali_Trojan_Time-Absence_Balances-Outbound"
exclude-result-prefixes="wd xsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<document>
<xsl:for-each select="wd:Report_Data/wd:Report_Entry/wd:All_Eligible_Time_Off_Plans_for_Worker">
<leaveBalanceTotal>
<employeeId><xsl:value-of select="parent::node()/wd:employeeId"/></employeeId>
<uscId><xsl:value-of select="parent::node()/wd:uscId"/></uscId>
<leaveCodeId><xsl:value-of select="wd:leaveCodeStr"/></leaveCodeId>
<balanceAmount><xsl:value-of select="wd:balanceAmount"/></balanceAmount>
<effectiveDate><xsl:value-of select="parent::node()/wd:effectiveDate"/></effectiveDate>
<totalDaysService><xsl:value-of select="parent::node()/wd:totalDaysService"/></totalDaysService>
<lastPayEndDate><xsl:value-of select="parent::node()/wd:lastPayEndDate"/></lastPayEndDate>
</leaveBalanceTotal>
</xsl:for-each>
</document>
</xsl:template>
</xsl:stylesheet>
这是我得到的输出:
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Sick</leaveDescription>
<leaveCodeStr>SS</leaveCodeStr>
<balanceAmount>90.22</balanceAmount>
<effectiveDate>03/11/2013 23:59:59</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>03/11/2013 23:59:59</lastPayEndDate>
</leaveBalanceTotal>
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Vacation</leaveDescription>
<leaveCodeStr>VA</leaveCodeStr>
<balanceAmount>187.11</balanceAmount>
<effectiveDate>03/11/2013 23:59:59</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>03/11/2013 23:59:59</lastPayEndDate>
</leaveBalanceTotal>
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Winter Recess</leaveDescription>
<leaveCodeStr>WR</leaveCodeStr>
<balanceAmount>30</balanceAmount>
<effectiveDate>03/11/2013 23:59:59</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>03/11/2013 23:59:59</lastPayEndDate>
</leaveBalanceTotal>
但是,我需要将两个日期字段转换为UNIX毫秒,并将日期转换为UNIX毫秒:
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Sick</leaveDescription>
<leaveCodeStr>SS</leaveCodeStr>
<balanceAmount>90.22</balanceAmount>
<effectiveDate>1363060799000</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>1363060799000</lastPayEndDate>
</leaveBalanceTotal>
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Vacation</leaveDescription>
<leaveCodeStr>VA</leaveCodeStr>
<balanceAmount>187.11</balanceAmount>
<effectiveDate>1363060799000</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>1363060799000</lastPayEndDate>
</leaveBalanceTotal>
<leaveBalanceTotal>
<employeeId>0001234</employeeId>
<uscId>1234567894654</uscId>
<leaveDescription>Winter Recess</leaveDescription>
<leaveCodeStr>WR</leaveCodeStr>
<balanceAmount>30</balanceAmount>
<effectiveDate>1363060799000</effectiveDate>
<totalDaysService>6062</totalDaysService>
<lastPayEndDate>1363060799000</lastPayEndDate>
</leaveBalanceTotal>
基本上我希望有人能告诉我如何转换这些日期。任何帮助将不胜感激。
答案 0 :(得分:2)
你可以通过将1970-01-01以来的持续时间除以1毫秒来获得自Unix时代以来的毫秒数。
例如,前缀xs:
绑定到名称空间URI http://www.w3.org/2001/XMLSchema
,以下XPath 2.0表达式
(xs:dateTime('2013-02-14T23:59:59') - xs:dateTime('1970-01-01T00:00:00'))
div xs:dayTimeDuration('PT0.001S')
评估为
1360886399000
已编辑添加:
要解析日期,您可能需要在XSLT 2.0中查看regular expression matching。例如,您可以编写一个函数,允许您将日期解析为xs:dateTime
值。
<!-- parses a dateTime value from a string of format "mm/dd/yyyy hh:mm:ss" -->
<xsl:function name="foo:parseDateTime" as="xs:dateTime">
<xsl:param name="input" as="xs:string"/>
<xsl:variable name="dateTimeLiteral">
<xsl:analyze-string select="normalize-space($input)"
regex="(\d\d)/(\d\d)/(\d\d\d\d)\s(\d\d):(\d\d):(\d\d)">
<xsl:matching-substring>
<xsl:number value="regex-group(3)" format="0001"/>
<xsl:text>-</xsl:text>
<xsl:number value="regex-group(2)" format="01"/>
<xsl:text>-</xsl:text>
<xsl:number value="regex-group(1)" format="01"/>
<xsl:text>T</xsl:text>
<xsl:number value="regex-group(4)" format="01"/>
<xsl:text>:</xsl:text>
<xsl:number value="regex-group(5)" format="01"/>
<xsl:text>:</xsl:text>
<xsl:number value="regex-group(6)" format="01"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:value-of select="xs:dateTime($dateTimeLiteral)"/>
</xsl:function>
你可以编写另一个函数来封装上面转换为毫秒的例子:
<!-- converts a dateTime into milliseconds since the beginning of 1970" -->
<xsl:function name="foo:toMilliseconds" as="xs:integer">
<xsl:param name="input" as="xs:dateTime"/>
<xsl:value-of select="(xs:dateTime($input)-xs:dateTime('1970-01-01T00:00:00'))
div xs:dayTimeDuration('PT0.001S')"/>
</xsl:function>
然后你可以将它们组合起来以毫秒为单位写日期,如下所示:
<xsl:value-of select="foo:toMilliseconds(foo:parseDateTime(lastPayEndDate))"/>