我可以看到两种可能的解释:
$param_item_group_id
包含多个节点。
- 有
product
多个 s item_group_id
:
例如,如果$param_item_group_id
看起来像这样:
[1] - <someNode>54655<someNode>
[2] - <someNode>354632<someNode>
你有一个product
这样的:
<product>
<item_group_id>354632</item_group_id>
<name>widgets</name>
<color>periwinkle</color>
</product>
The comparison would evaluate to true
(because they have a value in common), and the value-of
would produce 54644-354632-periwinkle
(because "54655" is the first node value in $param_item_group_id
). In the opposite case (one node in $param_item_group_id
and more than one item_group_id
in a product
), the same thing could happen.
That's only conjecture. I'd need to see your source XML and more of the XSLT to provide a more confident answer or help you remedy the issue.
I would expect this to prevent those incongruous outputs:
<xsl:if test="item_group_id[1] = $param_item_group_id[1]">
but I suspect there is a deeper underlying issue that this would not fix.
To clarify your questions from the comments:
The equality operator in XPath works differently from equality in a lot of other languages. Supposing A
or B
or both are node-sets, the expression A = B
will be true if any of the values in A
equal any of the values in B
. Hence my description above.
Regarding this question:
correct me if I'm wring, but this should not display if it was an array, right?
It would display. Passing a nodeset to concat()
converts it to a string value, and the string value of a nodeset is the string value of its first node. If the value of the first node in $param_item_group_id
is 54644, then that is what would display.
I think that $param_item_group_id
is exhibiting some behavior that you haven't pinned down and it's possible there's an issue in the way you're producing it. I'd suggest trying out the following to get a closer look at the contents of this variable:
<xsl:value-of select="concat('param_item_group_id contains ',
count($param_item_group_id),
' nodes.')" />
<xsl:for-each select="$param_item_group_id">
<xsl:value-of select="concat(., ', ')" />
</xsl:for-each>