我有 xslt2.0,我将其降级到 1.0 并使用 xalan,但出现以下异常。
可恢复错误:第 9 行:不支持的 XSL 元素“函数”。
xslt部分如下。
<xsl:function name="nav:adjustDate">
<xsl:param name="dateStr" />
<xsl:param name="age" />
<xsl:variable name="minutes">
<xsl:choose>
<xsl:when test="$age = 1">
<xsl:value-of select="0" />
</xsl:when>
<xsl:when test="$age = 2">
<xsl:value-of select="-10" />
</xsl:when>
<xsl:when test="$age = 3">
<xsl:value-of select="-20" />
</xsl:when>
<xsl:when test="$age = 4">
<xsl:value-of select="-30" />
</xsl:when>
<xsl:when test="$age = 5">
<xsl:value-of select="-40" />
</xsl:when>
<xsl:when test="$age = 6">
<xsl:value-of select="-50" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="-60" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="dateFormatterStr">
<xsl:text>yyyy-MM-dd'T'HH:mm:ss.SSSZ</xsl:text>
</xsl:variable>
<!-- output date format should match the input date format of the job file -->
<xsl:variable name="outDateFormatterStr">
<xsl:text>yyyy-MM-dd'T'HH:mm:ssZ</xsl:text>
</xsl:variable>
<xsl:variable name="bo" select="bool:new('FALSE')" />
<xsl:variable name="dateFormatter" select="dateFormat:new($dateFormatterStr)" />
<xsl:variable name="outDateFormatter" select="dateFormat:new($outDateFormatterStr)" />
<xsl:value-of select="dateFormat:setLenient($dateFormatter,$bo)" />
<!-- Have to remove the colon in the timezone offset(eg. +05:00) otherwise date formatter wont work correctly -->
<xsl:variable name="testDate"
select="dateFormat:parse($dateFormatter,concat(substring($dateStr,1,string-length($dateStr)-3),'00'))" />
<xsl:variable name="cal" select="gregorianCal:new()" />
<xsl:value-of select="gregorianCal:setTime($cal,$testDate)" />
<!-- xslt version 2 does not accept contants 12 represents the value for java.util.Calendar.MINUTE
Follow section of code will subtract the number of minutes-->
<xsl:value-of select="gregorianCal:add($cal,12,$minutes)" />
<xsl:variable name="outputDate" select="gregorianCal:getTime($cal)" />
<xsl:sequence select="dateFormat:format($outDateFormatter,$outputDate)" />
</xsl:function>
还想知道xslt1.0中xsl:sequence的替代品
有人可以指导我吗?如何进行 ? 我对 xslt 还很陌生。
最佳答案
如果您对 XSLT 相当陌生,那么将样式表从 XSLT 2.0 向后移植到 XSLT 1.0 可能会是一次非常痛苦的经历。祝你好运。
在 XSLT 1.0 中,通常可以在 XSLT 2.0 中使用函数的地方使用命名模板。您需要将外部 xsl:function 指令更改为 xsl:template,然后需要更改所有调用者以通过调用命名模板而不是调用函数来设置变量。最后,您需要将函数体转换为 XSLT 1.0。从调用其他用户声明函数初始化的大量变量来看,这将是一个非常缓慢的过程。
如果您的目标(或分配给您此任务的人的目标)是提供一个对样式表进行长期而深入的逐行研究的机会,这可能是一个好方法。否则,如果我是你,我建议重新考虑降级到 1.0 的决定。
关于java - 从xslt 2.0降级后如何在xslt1.0中编写函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16835737/