473,322 Members | 1,493 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,322 software developers and data experts.

XPath Expression trouble

I have the following bit of xhtml.

Code:

<td align="Right" class="grid"><i>One Dollars</i><br />
<a class="grid" href="http://www.orange.com">Orange</a><br />
<font class="detail">Fresh Oranges from the Florida </font></td>
<td align="Right" class="grid"><i>Two Dollars</i><br />
<a class="grid" href="http://www.banana.com">Banana</a><br />
<font class="detail">Fresh Bananas from the Dominican Republic</font></td>

I want to extract the price of the banana (two dollars) from it. Of
course there are many other fruits in this xhtml so the it has to
reference the Banana to get its specific price. I thought this would
involve something like this

Code:

<xsl:template match="htm:a[text()='Banana']/htm:previous-sibling">
<xsl:value-of select="."/>;
</xsl:template>

<xsl:template match="text()"/>

But this doesn't compile. Can anyone help?
Thanks
Nov 23 '05 #1
5 1033
In article <dl**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com>,
m0wax <no**@hotmail.com> wrote:
<xsl:template match="htm:a[text()='Banana']/htm:previous-sibling">
<xsl:value-of select="."/>;
</xsl:template>


That's completely confused!

You want something like

<xsl:template match="htm:a[text()='Banana']">
<xsl:value-of select="preceding-sibling::htm:i[1]"/>
</xsl:template>

-- Richard
Nov 23 '05 #2
> You want something like

<xsl:template match="htm:a[text()='Banana']">
<xsl:value-of select="preceding-sibling::htm:i[1]"/>
</xsl:template>


Or less graceful but still functional:

<xsl:template match="td[child::a[text() = 'Banana']]/i">
<xsl:value-of select="text()"/>
</xsl:template>

-- Lars

--
Lars Kellogg-Stedman <82*************@jetable.net>
This email address will expire on 2005-11-23.

Nov 23 '05 #3
Lars Kellogg-Stedman wrote:
Or less graceful but still functional:

<xsl:template match="td[child::a[text() = 'Banana']]/i">
<xsl:value-of select="text()"/>
</xsl:template>


Not in a namespace-aware context.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Nov 23 '05 #4
> Not in a namespace-aware context.

Do you mean that even if you were to qualify the element names it would
still be invalid, or are you just being pedantic because in my example they
weren't?

-- Lars

--
Lars Kellogg-Stedman <82*************@jetable.net>
This email address will expire on 2005-11-23.

Nov 23 '05 #5
Lars Kellogg-Stedman wrote:
Do you mean that even if you were to qualify the element names it would
still be invalid, or are you just being pedantic because in my example they
weren't?


The second.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Nov 23 '05 #6

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

Similar topics

14
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following...
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
1
by: David Laub | last post by:
I have no problems running the following dynamic XPath evaluator form MSXSL: <msxsl:script implements-prefix="dyn" language="jscript"> evaluate(context, expression) { return...
3
by: Opa | last post by:
Hi, I have and XMLDataSource which I am using in a GridView control and am customizing the grid with <ItemTemplate>. My XML datasource has an element with an attribute called "private". I want...
5
by: tschulken | last post by:
I have a query where i need to look for a value of a lower level xml element based on the value of a parent element existing first. Here is a simple example of the xml <S3Client> <Buttons>...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
4
by: piramido | last post by:
Hello, I'm in trouble with a simple XPath expression. I've got the following XML file <?xml version="1.0" encoding="UTF-8"?> <a> <b> <c>A</c> </b>
2
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can...
14
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.