How to use embedded EXSLT from XSLTProcessor?

风格不统一 提交于 2020-01-23 17:57:04

问题


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

回答1:


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>



回答2:


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



来源:https://stackoverflow.com/questions/1372810/how-to-use-embedded-exslt-from-xsltprocessor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!