如何使用 XSLTProcessor 中的嵌入式 EXSLT?

发布于 2024-08-03 06:56:04 字数 1096 浏览 4 评论 0原文

XSLTProcessor::hasExsltSupport() 返回 true。现在我需要修改什么才能使用它?

我有

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:date="http://exslt.org/dates-and-times"
                extension-element-prefixes="date">

我想要做的转换:

 <td>
   <xsl:value-of select="date:format-date(translate(property[@name='changedate']/value, ' ', 'T'), 'd.m.y h:i')" />
 </td>
  • property[@name='changedate']/value is stamp from SQL DB (yyyy-mm-dd hh:mm:ss)
  • 首先将该空格替换为 T 以便 exslt date-format 了解它
  • 更改 *yyyy-mm-dd** *T***时:分:秒* -> dd.mm.yyyy hh:mm

错误:

警告:XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]:xmlXPathCompOpEval:函数日期绑定到未定义的前缀格式

PHP 版本 5.2.9

  • XSL 启用
  • libxslt 版本 1.1.24
  • 针对 libxml 版本编译的 libxslt 2.6.32
  • EXSLT 启用
  • libexslt 版本 1.1.24

XSLTProcessor::hasExsltSupport() returns true. Now what do I have to modify so I can use it?

I have

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:date="http://exslt.org/dates-and-times"
                extension-element-prefixes="date">

Transformation what I'm trying to do:

 <td>
   <xsl:value-of select="date:format-date(translate(property[@name='changedate']/value, ' ', 'T'), 'd.m.y h:i')" />
 </td>
  • property[@name='changedate']/value is stamp from SQL DB (yyyy-mm-dd hh:mm:ss)
  • First replace that space to T so that exslt date-format understands it
  • Change *yyyy-mm-dd***T***hh:mm:ss* -> dd.mm.yyyy hh:mm

Error:

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: xmlXPathCompOpEval: function date bound to undefined prefix format

PHP version 5.2.9

  • XSL enabled
  • libxslt Version 1.1.24
  • libxslt compiled against libxml Version 2.6.32
  • EXSLT enabled
  • libexslt Version 1.1.24

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡写薰衣草的香 2024-08-10 06:56:04

我用这个修好了。它将日期信息移动到正确的位置。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template name="FormatDate">
    <xsl:param name="DateTime" />

    <xsl:variable name="mo">
      <xsl:value-of select="substring($DateTime, 6, 2)" />
    </xsl:variable>

    <xsl:variable name="day">
      <xsl:value-of select="substring($DateTime, 9, 2)" />
    </xsl:variable>

    <xsl:variable name="year">
      <xsl:value-of select="substring($DateTime, 1, 4)" />
    </xsl:variable>

    <xsl:variable name="time">
      <xsl:value-of select="substring($DateTime, 12, 8)" />
    </xsl:variable>

    <xsl:variable name="hh">
      <xsl:value-of select="substring($time, 1, 2)" />
    </xsl:variable>

    <xsl:variable name="mm">
      <xsl:value-of select="substring($time, 4, 2)" />
    </xsl:variable>

    <xsl:value-of select="$day" />
    <xsl:value-of select="'.'" />
    <xsl:value-of select="$mo" />
    <xsl:value-of select="'.'" />
    <xsl:value-of select="$year" />

    <xsl:value-of select="' '" />

    <xsl:value-of select="$hh" />
    <xsl:value-of select="':'" />
    <xsl:value-of select="$mm" />

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

I fixed it with this. It moves date information to correct positions.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template name="FormatDate">
    <xsl:param name="DateTime" />

    <xsl:variable name="mo">
      <xsl:value-of select="substring($DateTime, 6, 2)" />
    </xsl:variable>

    <xsl:variable name="day">
      <xsl:value-of select="substring($DateTime, 9, 2)" />
    </xsl:variable>

    <xsl:variable name="year">
      <xsl:value-of select="substring($DateTime, 1, 4)" />
    </xsl:variable>

    <xsl:variable name="time">
      <xsl:value-of select="substring($DateTime, 12, 8)" />
    </xsl:variable>

    <xsl:variable name="hh">
      <xsl:value-of select="substring($time, 1, 2)" />
    </xsl:variable>

    <xsl:variable name="mm">
      <xsl:value-of select="substring($time, 4, 2)" />
    </xsl:variable>

    <xsl:value-of select="$day" />
    <xsl:value-of select="'.'" />
    <xsl:value-of select="$mo" />
    <xsl:value-of select="'.'" />
    <xsl:value-of select="$year" />

    <xsl:value-of select="' '" />

    <xsl:value-of select="$hh" />
    <xsl:value-of select="':'" />
    <xsl:value-of select="$mm" />

  </xsl:template>
</xsl:stylesheet>
滿滿的愛 2024-08-10 06:56:04

“以下扩展函数被认为不稳定,并且不是 EXSLT - 日期和时间核心的一部分。声称支持 EXSLT - 日期和时间的处理器可能不支持这些函数。” - 这也适用于format-date

"The following extension functions are not considered stable and are not part of the core of EXSLT - Dates and Times. Processors that claim support of EXSLT - Dates and Times might not support these functions." - this applies to format-date as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文