Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2006, 06:46 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default selecting elements from comma separated list

I would like to know how I can select multiple nodes based on a comma-separated list.

for instance
I have a tree part
<address>
 ....
 <phone>123</phone>
 <fax>12345</fax>
 <ext>02231</ext>
 <email>abc@def.com</email>
</address>
and a list: mylist = "phone,ext"

When the active element is <email> I want to select all its sibling elements with the local-names based on the values in the list ("phone" and "ext")

what I want to select = ../*[local-name()='phone' or local-name()='ext'] based on a variable $mylist
 
Old September 29th, 2006, 06:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In 2.0:

../*[name()=tokenize($contactlist, ',')]

There's no tokenize() in 1.0, though there are equivalent extensions in some products. The best thing is to preconvert "phone,ext" into <list><kw>phone</kw><kw>ext</kw></list> and then you can write

../*[name()=$list/kw]



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 29th, 2006, 08:03 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx i tried this also but it gave a syntax error
../*[matches(local-name(),replace($mylist,',','|')]

but this worked
../*[matches(local-name(),'phone|ext']
isn't replace evaluated first (replace($mylist,',','|') gives phone|ext)?
 
Old September 29th, 2006, 08:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Thanx i tried this also but it gave a syntax error ./*[matches(local-name(),replace($mylist,',','|')]

Every programmer needs to learn to count brackets.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 29th, 2006, 08:46 AM
Authorized User
 
Join Date: May 2006
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

shame on me





Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a list box from comma separated values CoderNH Access VBA 3 October 20th, 2008 08:37 AM
convert list of ';' separated values --> elements Condor76 XSLT 1 June 11th, 2007 02:56 PM
Comma Separated values aldwinenriquez SQL Server 2005 3 June 1st, 2007 08:52 PM
comma separated list MunishBhatia SQL Server 2000 11 March 21st, 2007 03:56 PM
comma separated list of attributes rjonk XSLT 3 September 27th, 2006 11:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.