xsl-list
[Top] [All Lists]

Re: Using XPath to combine text from multiple nodes?

2005-08-31 08:00:59

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

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
concat(@first,@second)
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.

Employee/@first|Address/City

returns the node set that you require.

David

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________

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