2014-02-19 23 views
0

我正在使用XSLT 2.0並且有一個變量,其中包含以逗號分隔的日期。我嘗試來標記這個變量的for-each,但在執行中,我有錯誤:「不能選擇一個節點位置:上下文項是一個原子值」for-each上的上下文錯誤在標記變量上

這裏是我的代碼:

<xsl:variable name="datesMois"> 
    <xsl:call-template name="dayOfMonth"> 
     <xsl:with-param name="pDay" select="01" /> 
     <xsl:with-param name="pMonth" select="/workfile/query/@month" /> 
     <xsl:with-param name="pYear" select="/workfile/query/@year" />   
    </xsl:call-template> 
</xsl:variable> 
<xsl:variable name="currentstartdate" select="substring-before(., 'T')" /> 
<xsl:for-each select="tokenize($datesMois,',')"> 
    <xsl:variable name="dateJour" select="." /> 
... 

模板dayOfMonth返回參數中給出月份的天數。 我不明白我的代碼有什麼問題,請幫我一下?

謝謝。

+0

請在您的問題中添加更多_context_。也就是說,尤其是命名模板「dayOfMonth」的代碼 - 如果不是整個樣式表。另外,示例XML輸入將會有所幫助。 –

回答

0

假設你有類似

<xsl:variable name="datesMois"> 
    <xsl:call-template name="dayOfMonth"> 
     <xsl:with-param name="pDay" select="01" /> 
     <xsl:with-param name="pMonth" select="/workfile/query/@month" /> 
     <xsl:with-param name="pYear" select="/workfile/query/@year" />   
    </xsl:call-template> 
</xsl:variable> 
<xsl:variable name="currentstartdate" select="substring-before(., 'T')" /> 
<xsl:for-each select="tokenize($datesMois,',')"> 
    <xsl:variable name="dateJour" select="." /> 
    <xsl:value-of select="foo[date = $dateJour]"/> 

你會得到你所描述的錯誤,以避免你需要上下文節點之外的存儲換每一個變量作爲

<xsl:variable name="datesMois"> 
    <xsl:call-template name="dayOfMonth"> 
     <xsl:with-param name="pDay" select="01" /> 
     <xsl:with-param name="pMonth" select="/workfile/query/@month" /> 
     <xsl:with-param name="pYear" select="/workfile/query/@year" />   
    </xsl:call-template> 
</xsl:variable> 
<xsl:variable name="currentstartdate" select="substring-before(., 'T')" /> 

<xsl:variable name="context" select="."/> 

<xsl:for-each select="tokenize($datesMois,',')"> 
    <xsl:variable name="dateJour" select="." /> 
    <xsl:value-of select="$context/foo[date = $dateJour]"/> 

我不得不猜測你的代碼可能看起來如何導致錯誤,如果你仍然有問題,然後發佈導致錯誤的代碼的確切行。