XSLT中的日期转换 [英] Date conversion in XSLT
本文介绍了XSLT中的日期转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有这样日期的xml
I have a xml which has date like this
<tns:GoalsRequest>
<tns:accountNumber>23456</tns:accountNumber>
<tns:customerName>Smith</tns:customerName>
<tns:customerDOB>22-AUG-1981</tns:customerDOB>
<tns:searchBeginDate>13-DEC-1967</tns:searchBeginDate>
<tns:searchEndDate>08-DEC-1968</tns:searchEndDate>
</tns:GoalsRequest>
现在我想将日期转换为1981-08-22
在我的xsl中,我使用了
Now I want to translate date to 1981-08-22
In my xsl I used
<tns:customerDOB>
<xsl:value-of select="format-date(bi:customerDOB,'[D01]-[M01]-[YYYY]')"/>
</tns:customerDOB>
但出现以下错误
转换失败,词法值无效-xs:date''1981年8月22日
谁能帮助我转换此日期格式
谢谢
But I am getting the following error
cast failed, invalid lexical value - xs:date''22-AUG-1981
Can anybody helpme to convert this date format
Thanks
推荐答案
你好,
format-date将日期格式化为您选择的日期格式.
参见此处: http://www.w3.org/2005/xpath-functions/ [ ^ ]
在那里:
http://www.w3.org/TR/xmlschema-2/#date [ ^ ]
许多解析器会要求您要转换的日期具有2002-10-09T11:00:00之类的格式,因此08-DEC-1968将不会被识别.
解决此问题的一种方法是自己执行而不使用日期格式,例如:
Hello,
format-date formats a date into the date format of your choice.
see here : http://www.w3.org/2005/xpath-functions/[^]
and there:
http://www.w3.org/TR/xmlschema-2/#date[^]
Many parser will demand that the date you want to transform has a format like 2002-10-09T11:00:00, so 08-DEC-1968 will not be recognised.
A way to solve this is do it yourself and not use date-format, for example:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:value-of select="substring(customerDOB,8,4)" />
<xsl:variable name="month" select="substring(customerDOB,4,3)" />
<xsl:choose>
<xsl:when test="
月='JAN'" < > < xsl:何时 测试 ="
month = 'JAN'">-01-</xsl:when> <xsl:when test="
月='FEB'" < > < xsl:何时 测试 ="
month = 'FEB'">-02-</xsl:when> <xsl:when test="
这篇关于XSLT中的日期转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文