简体   繁体   中英

XSL choose when $variable = $variable

I'm trying to check if two XSL variables are the same:

<?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>

However, it's just skipping over both and not outputting anything.

Can anyone point out what I'm doing wrong?

You cannot "re-declare" variables in XSL. When you write

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

That has no affect, because of this

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

I can't help you though (yet), because I'm not really sure what you're trying to do

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM