2011-09-07 61 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

好吧。别客气! :-) –