Re: [xsl] concat all items in a sequence

Subject: Re: [xsl] concat all items in a sequence
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 31 Aug 2005 13:54:52 +0100
> contains(string-join(elem, ''), val)
>
> or (depending on what you want to do if val is a substring of the
> concatenation but not of any value, you may want
>
>
> true()=elem/contains(./val)

I was doing it within a predicate - an example is something like:

<root>
	<node>
		<text>abc</text>
	</node>
	<node>
		<text>def1</text>
		<text>def2</text>
	</node>
	<node>
		<text>ghi</text>
	</node>
</root>

I wanted to find the position of a <node> based on the value within <text>,
so:

<xsl:value-of select="count(.|/root/node[contains(text,
'def')]/preceding-sibling::node)"/>

This complains because one <node> contains two <text> elements, so
from the responses I've had I think the choices are:

[contains(string-join(text, ''), 'def')]

and

[some $x in text satisfies contains($x, 'def')]

As I want to check each value individually the latter suggestion from
Jarno is the one I'm using (plus its always nice to use 'some' and
'satisfies').

Also, string-join(text, '') with the empty quotes feels like a bit of
an abuse of the function - why wasn't there a single argument version
for this purpose?

Regarding true()=elem/contains(...) it's also really good using the
slash operator :) but I can't see how to squeeze it in here... (why
the true()= part david?)

Current Thread