[quoted text, click to view] Mark wrote:
> I have a c# class that i'm using to implement some extension functions and one of those functions is a simple push/pop stack. I made the c# code fairly generic, taking and returning objects - i.e.
> public void push (object val)
> { stack.Push (val);
> }
>
> public object pop ()
> { return stack.Pop();
> }
As stated on MSDN:
"The data types returned from extension objects are one of the four
basic XPath data types of number, string, Boolean, and node set."
You better obey to this rule if you want predictable behaviour.
[quoted text, click to view] > The thought was that the stack could be used for many purposes
Nitpickingly speaking that's really bad extension functions. They break
XSLT functional and side-effect free nature. Many would say that smells
like abusing extensions to change the language.
[quoted text, click to view] > <xsl:value-of select="ext:push(true())"/>
>
> With that presumption,
> <xsl:if test="ext:pop()">Succeeded!</xsl:if> fails
> <xsl:value-of select="string (ext:pop())"/> outputs 1
> <xsl:value-of select="boolean (ext:pop())"/> outputs false
Yeah, that's not really looks good. But as your function returns object
and there is no object type in XPath/XSLT data model, I think that's
quite reasonable to have such bizarre results.
[quoted text, click to view] > *but*
> <xsl:variable name="dummy" select="ext:pop()"/><xsl:if test="$dummy">Succeeded!</xsl:if> works
> <xsl:value-of select="string($dummy)"/> outputs true
> <xsl:value-of select="boolean($dummy)"/> outputs true
>
> Again, if i take the return from the extension function and pop it into a variable, it seems the interpretation as a boolean works fine but if I try to use the return from the extension function directly, it doesn't. Any ideas why that would be?
Well, once you bind object to a variable, it's being converted to one of
XPath data types, so it works properly.
--
Oleg Tkachenko [XML MVP]