473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A better xPath statement

I'm trying to pull out just three elements with a particular content
from a list of elements
my xml:

<content>
<topic>
<name>Sport</name>
....
</topic>
...
<topic>
<name>Health</name>
...
</topic>
.....
</content>
Here's what works in my xsl file, but there's probably a
better/easier/more efficient way of doing it:

<xsl:for-each select="topic[./name='Sports']| topic[./name='Movies']|
topic[./name='US News']">

Thanks in advance...martin

Jul 20 '05 #1
2 936

"mTbrains" <ma*************@gmail.com> writes:
I'm trying to pull out just three elements with a particular content
from a list of elements
my xml:

<content>
<topic>
<name>Sport</name>
....
</topic>
...
<topic>
<name>Health</name>
...
</topic>
....
</content>
Here's what works in my xsl file, but there's probably a
better/easier/more efficient way of doing it:

<xsl:for-each select="topic[./name='Sports']| topic[./name='Movies']|
topic[./name='US News']">

Thanks in advance...martin


well you could (always) drop the ./ as the Xpath is the same without
that.

then something like

<xsl:for-each select="topic[name='Sports' or name='Movies' or name='US
News']

or a bit shorter but perhaps a little less clear:

<xsl:for-each select="topic[name[.='Sports' or .='Movies' or .='US News']]

In XPath2 you will be able to do

<xsl:for-each select="topic[name=('Sports','Movies','US News')]

David
Jul 20 '05 #2


mTbrains wrote:
I'm trying to pull out just three elements with a particular content
from a list of elements
my xml:

<content>
<topic>
<name>Sport</name>
....
</topic>
...
<topic>
<name>Health</name>
...
</topic>
....
</content>
Here's what works in my xsl file, but there's probably a
better/easier/more efficient way of doing it:

<xsl:for-each select="topic[./name='Sports']| topic[./name='Movies']|
topic[./name='US News']">


topic[name = 'Sports' or name = 'Movies' or name = 'US News']

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3

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

Similar topics

8
by: Terry P | last post by:
Are there any tools (java classes, tag libraries) which can translate xpath statements into a SQL query? Given an xpath query which has a predicate that filters node values or attributes, I want...
6
by: Stefan Franke | last post by:
Hi, I've got a little bit of a problem when dealing with namespaces and XPath. I'm trying very basic things, like showing all the nodes of one particular namespace. Here is my XPath statement:...
4
by: gfrommer | last post by:
Hello everyone, I've been reading through a bunch of XPath tutorials and am confused by a couple items. First, is it possible to have multiple predicates in my XPath statement. For example, the...
1
by: bjam | last post by:
Hi, a quick basic question here on XPATH if I have the following data <X> <X1>TEST</X1> <Z> <Z1>Item 1</Z1> <Z2>Item 2</Z2> <Z3>Item 3</Z3>
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
1
by: Chris Fink | last post by:
What is a valid XPath Statement to retrieve the data found within the CDATA tag below? Using the XPath statement "/oid" returns "" <oid><!]></oid>
4
by: Daniel | last post by:
Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? string sdoc = "<foo><bar a='1'/><bar a='2'/></foo>";...
3
by: ziggyware | last post by:
Hi All, I have updated my XPath Generator software: XPath Studio .NET. ( http://www.ziggyware.com/downloads.php?cat_id=2 ) Easily select nodes from an xml file to generate XPath statements ...
2
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; In our program we will get an XPath statement such as: ${data}/SalesProject Where ${data} and ${series} both stand for a XPathNavigator so each is basically a specific node in a list of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.