xslt - 如何将此格式 mm/dd/yy 转换为 yyyy-mm-dd 并在 xslt 中添加 hh:mm:ss
问题描述
我想知道是否有人可以提供帮助。我一直在努力转换下面的日期。有没有办法将日期从 mm/dd/yy 转换为 yyyy-mm-dd 并在 xslt 中添加 hh:mm:ss?
这是我当前的输入 XML。我正在尝试转换“DateofService”。服务日期将始终为 mm/dd/yy,没有 hh:mm:ss。
<?xml version="1.0"?>
-<BCBSFMsg>
<BCBSFMsgHeader/>
-<BCBSFBody>
-<EIPMsg ImageType="PAPER" MsgType="DocumentNotify">
<ImageId>12344</ImageId>
<FileExtension>TIF</FileExtension>
<DateofService>11/27/18</DateofService>
<EIPMsg>
</BCBSFMsg>
目前,这是我在 xslt 中的查询:
<xsl:variable name="Date">
<xsl:variable name="sqlXref">
SELECT CONVERT(CHAR(19),ai.ADDLINFO_INDEX_15, 101) + '00:00:00' AS 'ServiceFromDate' FROM ADDITIONAL_INFORMATION ai with (nolock) INNER JOIN IMAGES_DETAIL id with (nolock) WHERE id.IMAGE_ID = '<xsl:value-of select="$IMAGE_ID"/>'
</xsl:variable>
<xsl:value-of select="env:ExecuteScalar($provider, $connStr, $sqlXref)"/>
</xsl:variable>
我$Date
在元素中传递变量
<xsl:element name ="DateofService">
<xsl:value-of select="$Date"/>
</xsl:element>
请指教。
谢谢你。
解决方案
如果您的输入 XML 包含:
<DateofService>11/27/18</DateofService>
然后是一个模板:
<xsl:template match="DateofService">
<xsl:copy>
<xsl:text>20</xsl:text>
<xsl:value-of select="substring-after(substring-after(., '/'), '/')"/>
<xsl:value-of select="format-number(substring-before(., '/'), '-00')"/>
<xsl:value-of select="format-number(substring-before(substring-after(., '/'), '/'), '-00')"/>
<xsl:text> 00:00:00</xsl:text>
</xsl:copy>
</xsl:template>
将返回:
<DateofService>2018-11-27 00:00:00</DateofService>
请注意,这假设您的所有日期都在 21 世纪。
推荐阅读
- c# - C# LINQ 在表上旋转
- ionic-framework - Ionic :app:processDebugGoogleServices (版本冲突)
- ffmpeg - ffmpeg 调整对比度,显示直方图
- wxpython - 如何更改状态文本在状态栏中的位置?
- c++ - 类外的前向声明有效,但嵌套时无效
- javascript - 类型错误:'addNode' 不是函数
- twitter-bootstrap - Tempus Dominus 中的时区
- python - Traceback(最近一次通话最后一次):和 TypeError:
- javafx - 是否可以将新节点或父节点添加到 javafx 中已加载的 fxml 文件?
- java - 尝试将数组中的元素与 for 循环组合