Hi, David.
David Portabella Clotet <[EMAIL PROTECTED]> wrote on 2006-01-18
12:39:21 PM:
> If I run the compact simple example provided at the end, I get this
result.
>
> <test>
> <a>Hello</a>
> <b/>
> <c>World</c>
> </test>
>
> For 'a' and 'c' it works as expected, but I do not understand the
> behaviour of 'b'.
...
> xml file:
> <test>
> <t1>
> <t2>Hello</t2>
> <t2>World</t2>
> </t1>
> </test>
>
> stylesheet:
> <xsl:template match="/test">
> <test>
> <a><xsl:value-of select="t1[t2='World']/t2"/></a>
> <b><xsl:value-of select="t1[normalize-space(t2)='World']/t2"/></b>
> <c><xsl:value-of select="t1/t2[.='World']"/></c>
> </test>
> </xsl:template>
I don't know whether anybody ever responded to your question, so I
hope you figured out the problem a long time ago.
In any event, for the expression, t1[t2='World']/t2 the expression t2
in the predicate results in a node-set containing the two child element
nodes of t1. According to section 3.4 of XPath,[1] if one object in
relational or equality expression is a node-set and the other is a string,
the result of the expression is true if and only if there is a node for
which the expression is true. The comparison is true for the second t2
node, so the predicate is true.
For the expression t1[normalize-space(t2)='World']/t2, the expected
argument type for normalize-space is "string?". According to section 3.2
of XPath,[2] an argument to a function will be converted to the expected
type - for string, the conversion is performed as if by the string
function.[3] Given a node-set as its argument, the string function
returns the string value of the node that is first in document order. In
this case, the argument to normalize-space is effectively the string value
of the first t2 node, "Hello", so the value of the predicate is false.
This might be what you're looking for, though I can't be certain,
since you didn't actually describe what result you needed.
<d><xsl:value-of select="t1[t2[normalize-space(.)='World']]/t2"/></d>
I hope that helps.
Thanks,
Henry
[1] http://www.w3.org/TR/xpath#booleans
[2] http://www.w3.org/TR/xpath#section-Function-Calls
[3] http://www.w3.org/TR/xpath#function-string
------------------------------------------------------------------
Henry Zongaro Xalan development
IBM SWS Toronto Lab T/L 969-6044; Phone +1 905 413-6044
mailto:[EMAIL PROTECTED]