【问题标题】:Required item type of first argument of substring() is xs:string; supplied value has item type xs:dateTimesubstring() 的第一个参数需要的项目类型是 xs:string;提供的值具有项目类型 xs:dateTime
【发布时间】:2020-03-05 18:57:11
【问题描述】:
  <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   version="2.0"

    exclude-result-prefixes="#all"
    >
  <xsl:output indent="yes"/>
  <xsl:template match="/">
  <xsl:variable name="utc-timestamp" select="current-dateTime()"/>
  <xsl:variable name="gmt-timestamp" select="adjust-dateTime-to-timezone($utc-timestamp, xs:dayTimeDuration('PT0H'))"/>
  <xsl:variable name="eu-timestamp" select="adjust-dateTime-to-timezone($utc-timestamp, xs:dayTimeDuration('PT1H'))"/>
  <xsl:variable name="est-timestamp" select="adjust-dateTime-to-timezone($utc-timestamp, xs:dayTimeDuration('-PT5H'))"/>

  <xsl:variable name="fcccYear" select="substring($est-timestamp,7,2)"/>


      <date timestamp="{$utc-timestamp}">
      <gmt str="{$gmt-timestamp}">
        <xsl:value-of select="$fcccYear"/>

      </gmt>
      <est str="{$est-timestamp}">
          <xsl:value-of select="format-dateTime($est-timestamp, '[D01][M01][Y0001][h]:[m][PN,*-2] [ZN,*-3]', (), (), 'us')"/>
      </est>

  </date>
  </xsl:template>
  </xsl:stylesheet>

我正在尝试获取调整时间的子字符串,但我得到了以下错误,这很好。有人可以告诉我如何将 XS:dateTime 转换为 XS:String

错误:substring() 的第一个参数的必需项类型是 xs:string;提供的值具有项目类型 xs:dateTime

【问题讨论】:

  • 请选择XSLT的一个版本标签,而不是全部。
  • 当然。我删除了其他标签

标签: xml xslt xslt-2.0


【解决方案1】:

dateTime 或 date 数据类型具有提取月份或年份等组件的功能;此外,您还知道format-dateTime,它使用正确的第二个参数可以让您获得包含任何部分和任何您想要的格式的字符串。如果你想要一个字符串,你也可以使用string($est-timestamp)

【讨论】:

    【解决方案2】:

    您可以将xs:dateTime 转换为xs:string。所以这条线可能是

    <xsl:variable name="fcccYear" select="substring(xs:string($est-timestamp),7,2)"/>
    

    【讨论】:

    • 事实上,string()xs:string() 函数都可以正常工作(它们几乎在所有情况下都是等效的)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 2021-02-05
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    相关资源
    最近更新 更多