473,472 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Comma separated list using XPath

Can anyone think of a changing these XPath expressions to return comma
separated lists?

/Library/Branch/book/(if(author="John") then position() else "")
output: 1 3 5
desired output: 1, 3, 5

/Library/Branch/book/(if(author="Mary") then position() else "")
output: 2
desired output: 2

/Library/Branch/book/(if(author="Mark") then position() else "")
output: 4
desired output: 4

<Library>
<Branch>
<book>
<author>John</author>
</book>
<book>
<author>Mary</author>
</book>
</Branch>
<Branch>
<book>
<author>John</author>
</book>
<book>
<author>Mark</author>
</book>
<book>
<author>John</author>
</Branch>
</Library>
Nov 30 '07 #1
5 4249
ni********@gmail.com wrote:
Can anyone think of a changing these XPath expressions to return comma
separated lists?
XPath itself just retrieves information; formatting it is someone else's
job. You'd want something more like XSLT or XQuery, which can generate
new structure around the extracted data. Or you'd need to invoke the
XPath from a bit of code which generated the appropriate wrapper text.
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 30 '07 #2

"Joseph Kesselman" <ke************@comcast.netwrote in message
news:47508444$1@kcnews01...
ni********@gmail.com wrote:
>Can anyone think of a changing these XPath expressions to return comma
separated lists?

XPath itself just retrieves information; formatting it is someone else's
job. You'd want something more like XSLT or XQuery, which can generate new
structure around the extracted data. Or you'd need to invoke the XPath
from a bit of code which generated the appropriate wrapper text.

Not quite so ...

The evaluation of this expression:

"/Library/Branch/book
/(if(author='John')
then concat(position(),
if(not(position() eq last()))
then ','
else ''
)
else ()
)"

produces the wanted results:

1, 3, 5
Cheers,
Dimitre Novatchev
Dec 1 '07 #3
Joseph Kesselman wrote:
ni********@gmail.com wrote:
>Can anyone think of a changing these XPath expressions to return comma
separated lists?

XPath itself just retrieves information; formatting it is someone else's
job.
No longer quite true for XPath 2.0 which the original poster seemed to
use anyway.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 1 '07 #4
/(if(author='John')

I believe if/then/else expressions require XPath 2.0 or XQuery. If
that's what you have available, go for it; if you're using 1.0...

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Dec 1 '07 #5

"Joe Kesselman" <ke************@comcast.netwrote in message
news:gq******************************@comcast.com. ..
> /(if(author='John')

I believe if/then/else expressions require XPath 2.0 or XQuery. If that's
what you have available, go for it;
Yes, this was the code in the OP first post.
Cheers,
Dimitre Novatchev
Dec 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Keightley | last post by:
I can do the match perfectly but what i also need to do is create a third list of comma separated values that are in both eg: List 1 => 1,2,3,4,5,6,7,8,11 List 2 => 1,3,4,5,6,7,10,23 ...
26
by: Christina | last post by:
I have a post-form that holds a listbox with mulitple selected items. When the form is posted to the server ASP file, I want to loop through the selected items, to insert each of them into a table....
1
by: Not Me | last post by:
Hi, I'm sure this is a common problem.. to create a single field from a whole column, where each row would be separated by a comma. I can do this for a specified table, and column.. and I've...
12
by: insomniux | last post by:
Hi, I'n in an environment where I cannot make stored procedures. Now I need to make a query with a subquery in the SELECT part which gives a comma separated list of results: SELECT p.id,...
5
by: Bob | last post by:
I think this is very simple but I am having difficult doing it. Basically take a comma separated list: abc, def, ghi, jk A list with only one token does not have any commas: abc The first...
7
by: Hermann | last post by:
I run a server with apache 1.3 and php 5. Yesterday I notice that sometimes the HTTP_HOST server variable has a comma separated list in it. Let's say my domain name is: www.mydomain.com Usually...
2
Haitashi
by: Haitashi | last post by:
I have a comma delimited list of the following elemente: sites.app.enroll.page5.degrees.gfdg, sites.app.enroll.page5.degrees.aeetr, sites.app.enroll.page5.degrees.sfdsd,...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.