2013-05-30 33 views
1

我有xslt2.0,我降級到1.0並使用xalan,但得到以下異常。如何在xslt 2.0中降級後在xslt1.0中寫入函數

可恢復的錯誤:第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> 

也想知道XSL替代:在xslt1.0

序列有人能指導我這個?如何進行 ? 對於xslt來說相當新穎。

回答

1

如果您對XSLT相當陌生,那麼將樣式表從XSLT 2.0移回XSLT 1.0可能是一個非常痛苦的體驗。祝你好運。

在XSLT 1.0中,通常可以在XSLT 2.0中使用命名模板,其中一個使用函數。您需要將外部xsl:function指令更改爲xsl:template,然後您需要更改所有調用者以通過調用命名模板而不是通過調用該函數來設置變量。最後,您需要將函數的主體轉換爲XSLT 1.0。通過調用其他用戶聲明函數初始化的大量變量來判斷,這將是一個非常緩慢的過程。

如果您的目標(或分配給您這項任務的人的目標)是爲長時間,密集的逐行研究樣式表提供機會,這可能是一種好方法。否則,如果我是你,我會建議重新考慮降級到1.0的決定。