Re: [xsl] Using XPath to combine text from multiple nodes?

Subject: Re: [xsl] Using XPath to combine text from multiple nodes?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 31 Aug 2005 16:00:59 +0100
> Is there any way to write an XPath expression that will combine the
> text within two nodes and return a text node that contains the
> combined strings.

No, not without using a user-supplied function as Xpath does not
generate new nodes, it only returns node in the source, or atomic
values. Howver an XPath function could do this (and in xslt2 you can
write xpath functions using xslt rather than using an extension

But probably you don't _really_ need a text node do you?  wouldn't you
be happy with a returned string?

> Although I don't think this would affect any solutions, the xpath
> processor is the .Net Framework v1.1. 

Only in so far as it means that you are looking for an xpath1 solution
which rather limits things here as xpath1 doesn't have "node lists"
which is what you are asking for but "node sets", which have no order.

> <Employee first="Mark" second="Allanson" />
> What I would like to do in this case is to effectively return a node
> that contains the text "MarkAllanson". 

as I say you can't return a text node but you could return the string
it depends what you want to do with it after that.

> Is it possible to write an XPath to return a node list that contains
> both the first attribute of the employee and the City element of the
> address? 

yes of course, except that attribute order is implementation defined so
it's best to select attribute by name rather than number as @*[1]
is legal but selects an essentially arbitrary attribute.


returns the node set that you require.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread