Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XPATH 2.0 select a certain set of attributes and concat them.

0 views
Skip to first unread message

Sharat Koya

unread,
Jul 27, 2007, 11:18:19 AM7/27/07
to
I have a the following xml node.

<doc tag1="a" tag2="b" tag3="c" docTag1="d" docTag2="e"/>

I would like to output "abc"

I have the following XPATH2.0 so far

//doc/@*[name()[starts-with(.,'tag')]] which returns a node list.

Is there a better way of concatinating these?

thanks in advance for any advice

Martin Honnen

unread,
Jul 27, 2007, 11:39:45 AM7/27/07
to
Sharat Koya wrote:
> I have a the following xml node.
>
> <doc tag1="a" tag2="b" tag3="c" docTag1="d" docTag2="e"/>
>
> I would like to output "abc"
>
> I have the following XPATH2.0 so far
>
> //doc/@*[name()[starts-with(.,'tag')]] which returns a node list.
>
> Is there a better way of concatinating these?

XPath 2.0 has a function string-join which you could use e.g.
string-join(//doc/(@tag1 | @tag2 | @tag3), '')


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Sharat Koya

unread,
Jul 27, 2007, 11:52:10 AM7/27/07
to

Sorry I should have said I don't know how many attributes there could
be. There will be 1 or more - is the string-join function capable of
processing x number of attributes?


Martin Honnen

unread,
Jul 27, 2007, 12:03:31 PM7/27/07
to
Sharat Koya wrote:

>> XPath 2.0 has a function string-join which you could use e.g.
>> string-join(//doc/(@tag1 | @tag2 | @tag3), '')

> Sorry I should have said I don't know how many attributes there could


> be. There will be 1 or more - is the string-join function capable of
> processing x number of attributes?

Well your original code already solved that problem, simply apply
string-join to the attributes where the name starts with 'tag' e.g.
string-join(//doc/@*[starts-with(local-name(), 'tag')], '')

Sharat Koya

unread,
Jul 27, 2007, 12:12:26 PM7/27/07
to

ah of course. thanks for your time.

0 new messages