Hi,
It seems that it might be useful to determine if the context item is set.
Of course, currently, the best is to keep it set at all times, it works,
even if it is not always very pretty.
Using something like you suggested or like this:
<xsl:template name="abc">
<xsl:param name="target" select="."/>
<xsl:message>
<xsl:for-each select="$target">
<xsl:copy-of select="."/>
</xsl:for-each></xsl:message>
</xsl:template>
Still fails if the context item is not set, prior to invocation.
As David pointed out, the most usual case is calling one of these
push&pull templates from a function, prior to (re-)setting the context node.
There must have been a good reason for functions not to inherit the
calling context item, at least until they change it, like in (called)
templates ...
It can be quite useful to initialize parameters from the context node as
in ...
<xsl:param name="status" select="if (string(@status) then @status else
'new'"/>
where, if context item is not set, then $status = 'new', for example.
Ensuring that the context node is set at all times, does the trick.
Thanks for the info.
Cheers,
ac
Michael Kay a écrit :
Why error "The context item is not set", when the context is
not set, on something like this:
<xsl:value-of select="if (.) then 'a' else 'b'"/> How else
does one check if the context item is set?
There's no way to test whether the context item is currently set. I think
the only case where you can't tell statically is probably within a named
template. I think it's probably good practice for a named template to
declare a parameter:
<xsl:param name="target" select="."/>
and within the body of the template to refer to $target rather than ".". The
caller must then either pass over a context item, or set the value of
$target explicitly.
Michael Kay
http://www.saxonica.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--