用于匹配日期时间格式的 xpath [英] xpath for matching DateTime format

查看:36
本文介绍了用于匹配日期时间格式的 xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 xslt 来查找具有特定日期格式的所有元素.但是match"语句似乎有问题.我需要使用 C# 代码将此日期格式化为自定义格式.任何帮助都会很棒..

Im writing an xslt to find all elements with specific Date formats. But the "match" statement seems to be a problem. I need to format this date to a custom format using C# code. Any help would be great..

我的 XSLT 是:

  <xsl:template match="text()[.='[M01]/[D01]/[Y0001]']">
    <xsl:value-of select="userCSharp:GetFormatedDate(.)" />
  </xsl:template>

我的 Xml 是:

<Root>
<Name>Don</Name>
<EffectiveDate>01/30/2015</EffectiveDate>
</Root>

推荐答案

我想您正在使用 XSLT 1.0?如果是这样,请尝试:

I presume you are using XSLT 1.0? If so, try:

<xsl:template match="text()[translate(., '123456789', '000000000') = '00/00/0000']">
    <xsl:value-of select="userCSharp:GetFormatedDate(.)" />
</xsl:template>

请注意,这匹配具有 ##/##/#### 模式的任何 文本节点.它检查MM/DD/YYYY 格式的有效日期.99/99/9999 的日期"也会通过此测试.

Note that this matches any text node having a pattern of ##/##/####. It does not check for a valid date in MM/DD/YYYY format. A "date" of 99/99/9999 would pass this test too.

这篇关于用于匹配日期时间格式的 xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆