简体   繁体   English

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

[英]How to use embedded EXSLT from XSLTProcessor?

XSLTProcessor::hasExsltSupport() returns true. XSLTProcessor :: hasExsltSupport()返回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) 属性[@ name ='changedate'] /值是来自SQL DB的标记(yyyy-mm-dd hh:mm:ss)
  • First replace that space to T so that exslt date-format understands it 首先将该空间替换为T,以便exslt日期格式可以理解它
  • Change *yyyy-mm-dd***T***hh:mm:ss* -> dd.mm.yyyy hh:mm 更改* 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 警告:XSLTProcessor :: transformToXml()[xsltprocessor.transformtoxml]:xmlXPathCompOpEval:函数日期绑定到未定义的前缀格式

PHP version 5.2.9 PHP版本5.2.9

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

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>

"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." “以下扩展功能不是稳定的,也不属于EXSLT-Dates and Times的核心。声称支持EXSLT-Dates and Times的处理器可能不支持这些功能。” - this applies to format-date as well. -这也适用于format-date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM