XPath Expression trouble

M

m0wax

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
 
R

Richard Tobin

m0wax said:
<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
 
L

Lars Kellogg-Stedman

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
 
J

Johannes Koch

Lars said:
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.
 
L

Lars Kellogg-Stedman

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
 
J

Johannes Koch

Lars said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top