xpath for matching DateTime format

2019-09-10 07:35发布

问题:

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..

my XSLT is:

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

My Xml is:

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

回答1:

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>

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.



标签: c# xml xslt xpath