xsl-list
[Top] [All Lists]

Re: [xsl] When to use text()

2014-03-21 11:12:03
On 21/03/2014 15:15, David Sewell wrote:
I wonder how much of the problem (and there is one, at least for
beginning users of XPath/XQuery/XSLT, and it even bites old hands
sometimes) is owing to the fact that the XPath syntax for an axis
step followed by a node type is identical to the syntax for an axis
step followed by a single-argument function.

$node/text()

looks just like

$node/string()

even though the underlying semantics are quite different. I suspect
that mentally one tends to conflate the two. (Applying the
Sapir-Whorf hypothesis to programming languages, i.e. the way a
language encodes things influences the way we think about them.)

David



The single argument function form is of course a lot later (xpath2) than
the text() node step. But actually they can be seen as the same thing.
If I define a user-defined function my:text(n) that returns the text
node children of the input node n

<xsl:function name="my:text">
<xsl:param name="n"/>
<xsl:sequence select="$n/text()"/>
</xsl:function>

then

$node/text()

and

$node/my:text(.)

are the same thing. the only magic part is that user-defined functions
can not default the context node, so the syntax has to be


$node/my:text(.)


rather than


$node/my:text()



Basically all axis steps can be seen as syntactic sugar for functions
that default to the context node and return a sequence of nodes.


David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________

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

<Prev in Thread] Current Thread [Next in Thread>