我想对使用XSL的日期进行一些操作。我用这个脚本在IBM developerWorks上找到了一个教程。找不到外部方法“...”(必须是公开的)XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
version="1.0"
>
<xsl:output method="html"/>
<!-- B -->
<xsl:variable name="now" select="date:date-time()"/>
<xsl:template match="/">
<!-- The rest of the Web site HTML material would go here -->
<xsl:call-template name="date-section"/>
</xsl:template>
<xsl:template name="date-section">
<p>This page was loaded at <xsl:text/>
<!-- C -->
<xsl:value-of select="concat(date:hour-in-day($now), ':',
date:minute-in-hour($now), ':',
date:second-in-minute($now))"/>
<xsl:text> on </xsl:text>
<xsl:value-of select="concat(date:day-in-month($now), ' ',
date:month-name($now), ' ',
date:year($now))"/>
</p>
<p>
<!-- D -->
<xsl:variable name="days-elapsed"
select="concat('-P',date:day-in-month($now),'D')"/>
<xsl:variable name="one-month-hence"
select="date:add($now, 'P1M')"/>
<xsl:variable name="next-month-start"
select="date:add($one-month-hence, $days-elapsed)"/>
<xsl:variable name="seconds"
select="date:seconds(
date:difference($now, $next-month-start)
)"/>
<xsl:text>The next month starts in </xsl:text>
<xsl:value-of select="$seconds div (3600*24)"/>
<xsl:text> days</xsl:text>
</p>
</xsl:template>
我收到以下错误:
[ERROR]: Cannot find external method 'com.sun.org.apache.xalan.internal.lib.ExsltDatetime.add' (must be public).
[ERROR]: Cannot find external method 'com.sun.org.apache.xalan.internal.lib.ExsltDatetime.difference' (must be public).
[ERROR]: Cannot find external method 'com.sun.org.apache.xalan.internal.lib.ExsltDatetime.seconds' (must be public).
[ERROR]: Cannot convert data-type 'void' to 'real'.
[FATAL]: Could not compile stylesheet
任何想法如何解决它。我正在使用IntelliJ来运行xsl。
最终我想能够添加日期到一个日期。由于某种原因,当我尝试使用xsl 2日期函数时,它只是告诉我它们不存在(是的,我将标题更改为版本2 :))。所以我试图让它与第三方库一起工作。 日期时间()函数来自http://exslt.org/dates-andtimestimes命名空间正在工作,但我无法缝制能够调用其他函数形成该命名空间。
JustmeVSI,这是不足以改变XSL的版本属性:样式表。您*必须*拥有XSLT 2.0处理器。 –
@DimitreNovatchev我刚刚搜索了XSLT 2.0处理器,但没有得到太多有用的信息。你能否详细说明一下。就像我如何设置它,什么是必要的? – JustmeVSI
JustmeVSI,您需要有Saxon 9.x,Altova2012(XMLSpy)或XQSharp(XMLPrime)之一。您可以轻松找到他们的网站和下载。 –