Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath Expression trouble

Reply
Thread Tools

XPath Expression trouble

 
 
m0wax
Guest
Posts: n/a
 
      11-22-2005
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']/htmrevious-sibling">
<xsl:value-of select="."/>;
</xsl:template>

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



But this doesn't compile. Can anyone help?


Thanks
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      11-22-2005
In article <dlvq0c$qh6$(E-Mail Removed)-infra.bt.com>,
m0wax <(E-Mail Removed)> wrote:

><xsl:template match="htm:a[text()='Banana']/htmrevious-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
 
Reply With Quote
 
 
 
 
Lars Kellogg-Stedman
Guest
Posts: n/a
 
      11-22-2005
> 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 <(E-Mail Removed)>
This email address will expire on 2005-11-23.

 
Reply With Quote
 
Johannes Koch
Guest
Posts: n/a
 
      11-22-2005
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)
 
Reply With Quote
 
Lars Kellogg-Stedman
Guest
Posts: n/a
 
      11-22-2005
> 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 <(E-Mail Removed)>
This email address will expire on 2005-11-23.

 
Reply With Quote
 
Johannes Koch
Guest
Posts: n/a
 
      11-23-2005
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.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments