2016-11-14 11 views
0

xslt2に2つの変数を追加しようとしています。アイデアは次の月を持つことです。net.sf.saxon.trans.XPathException:型の引数に算術演算子が定義されていません(xs:string、xs:string)

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" exclude-result-prefixes="xsl xs fn xdt"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/"> 
    <xsl:param name="filter_date"/> 

    <xsl:variable name="Current_Date"> 
     <xsl:choose> 
      <xsl:when test="$filter_date"> 
       <xsl:value-of select="$filter_date"/> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="format-date(current-date(), '[Y0001][M01][D01]')"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:variable> 

    <xsl:variable name="Current_Month" select="substring($Current_Date,5,2)"/> 
    <xsl:variable name="Current_Year" select="substring($Current_Date,1,4)"/> 
    <xsl:variable name="One">1</xsl:variable> 

    <xsl:variable name="Month"> 
     <xsl:choose> 
      <xsl:when test="$Current_Month = '12'"> 
       <xsl:text>01</xsl:text> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="$Current_Month + '0' + $One"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:variable> 

    <xsl:variable name="Year"> 
     <xsl:choose> 
      <xsl:when test="$Current_Month = '12'"> 
       <xsl:value-of select="sum($Current_Year + $One)"/> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="$Current_Year"/> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:variable> 

    <out> 
     <xsl:value-of select="concat($Year, $Month, '20')" /> 
    </out> 

</xsl:template> 

しかし、私はエラー

net.sf.saxon.trans.XPathException取得::私はコードを使用しています

は以下の通りです算術演算子が定義されていませんが型の引数(xs:string、xs:string)

答えて

0

あなたがXSLT/XPath 2.0の中で日付の計算をしたい場合は、単純に現在の日付を使用することに月

+に文字列を追加する
<xsl:value-of select="current-date() + xs:yearMonthDuration('P1M')"/> 

を追加するたとえば、日付に期間を追加することができますXSLT/XPathではサポートされていませんが、文字列の連結を期待するか、オペランドを最初に数値に変換するかはわかりません。

+0

お返事ありがとうございました。この機能は役に立ちます:)良い一日を。 – Vicky

関連する問題