2011-09-07 64 views
0

我想檢查兩個XSL變量是相同的:

<?xml version="1.0" encoding="UTF-8"?> 
<files> 
<file filename="export.csv" path="/export" active="true" ftp="false"> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl"> 
<xsl:output method="text" encoding="UTF-8"/> 
<xsl:variable name="quote">"</xsl:variable> 
<xsl:variable name="sepstart" select="'&#44;'"/> 

<xsl:template match="/"> 
<xsl:text>"CustomerID"</xsl:text> 

<xsl:variable name="second_check">0</xsl:variable> 

<xsl:for-each select="orders/order"> 
<xsl:for-each select="items/item"> 

<xsl:variable name="output"> 
<xsl:variable name="first_check"><xsl:value-of select="normalize-space(../../increment_id)"/></xsl:variable> 

<xsl:choose> 
<xsl:when test="$first_check = $second_check"> 

Do something... 

</xsl:when> 
<xsl:otherwise> 

Do something... 

<xsl:variable name="second_check"><xsl:value-of select="normalize-space(../../increment_id)"/></xsl:variable> 

</xsl:otherwise> 
</xsl:choose> 

</xsl:variable> 
<xsl:value-of select="$output" /> 
<xsl:text>&#xD;</xsl:text> 

</xsl:for-each> 

</xsl:for-each> 
</xsl:template> 

</xsl:stylesheet> 
</file> 
</files> 

然而,它只是跳過兩並且不輸出任何東西。

任何人都可以指出我做錯了什麼?

+4

對我來說沒問題。也許你需要向我們展示一些真實的代碼。 –

+1

...和一些輸入XML –

+0

爲您添加了一些真實的代碼...可能有幫助...我可以粘貼它,因爲我正在生成一個巨大的出口!頭文持續多年 –

回答

1

您不能在XSL中「重新聲明」變量。當你寫

<xsl:variable name="second_check"> 
    <xsl:value-of select="normalize-space(../../increment_id)"/> 
</xsl:variable> 

這沒有影響,因爲這個

<xsl:variable name="second_check">0</xsl:variable> 

我幫不了你,但(還),因爲我真的不知道你想做什麼

+0

那麼你剛剛回答我的問題我試圖重新聲明我的變量與每個循環,這就是我要去哪裏錯了。那麼非常感謝 –

+0

好吧。別客氣! :-) –