Re: [xsl] When to use text()

Subject: Re: [xsl] When to use text()
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 21 Mar 2014 16:11:45 +0000
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.


looks just like


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.)


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()"/>





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


rather than


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


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. ________________________________________________________________________

Current Thread