2013-05-06 109 views
0

我需要驗證XSLT中Invoice元素的值:缺少元素=默認爲1(工作)... blank =默認爲1(工作)...但是2或字符串中的任何數字這是不工作,因爲它保持返回到1.修復xslt驗證錯誤

<xsl:template match="Transaction" > 
    <Transaction invoice="{Invoice}"> 
    <xsl:attribute name="invoice"> 
     <xsl:choose> 
     <xsl:when test="@Invoice and (@Invoice!='') and (@Invoice!='0')"> 
     <xsl:value-of select="@Invoice"/></xsl:when> 
     <xsl:otherwise>1</xsl:otherwise> 
     </xsl:choose> 
    </xsl:attribute> 
</xsl:template> 

希望得到你的任何幫助。會很感激。

感謝

+0

是發票的屬性或您的輸入XML的節點?看起來,你總是在你的默認分支中運行。 'invoice =「{Invoice}'這是使用Invoice作爲節點,但'@ Invoice'正在查找Invoice as attribute。 – 2013-05-06 15:05:51

+0

您的問題尚不清楚,但如果您向我們展示了一個例子,我們可能會回答它一個事務元素在你的源文件中 – 2013-05-06 17:26:47

回答

0

when病症使用的,而是和 (好像只有小寫是好的)

開始從一個簡單的條件,並添加一次一個,看看哪一個是壞的:

<xsl:when test="@Invoice"> 

然後

<xsl:when test="@Invoice and (@Invoice!='')"> 

然後

<xsl:when test="@Invoice and (@Invoice!='') and (@Invoice!=0)"> 

althoug我會寫

<xsl:when test="@Invoice and (@Invoice &gt; 0)"> 
+0

這是行不通的,我得到了錯誤的結果 – user1358072 2013-05-06 14:01:56

+0

最後一行不能大於0,因爲它是一個字符串 – user1358072 2013-05-06 14:11:55

+0

對不起,你的問題看起來它們是數字(「.. .. 。但2或任何數字不工作,因爲它保持返回1'「) – ilomambo 2013-05-06 14:19:57