XPath Expression trouble

Discussion in 'XML' started by m0wax, Nov 22, 2005.

  1. m0wax

    m0wax Guest

    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
     
    m0wax, Nov 22, 2005
    #1
    1. Advertising

  2. In article <dlvq0c$qh6$-infra.bt.com>,
    m0wax <> 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
     
    Richard Tobin, Nov 22, 2005
    #2
    1. Advertising

  3. > 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 <>
    This email address will expire on 2005-11-23.
     
    Lars Kellogg-Stedman, Nov 22, 2005
    #3
  4. 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)
     
    Johannes Koch, Nov 22, 2005
    #4
  5. > 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 <>
    This email address will expire on 2005-11-23.
     
    Lars Kellogg-Stedman, Nov 22, 2005
    #5
  6. 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.)
     
    Johannes Koch, Nov 23, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,976
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,417
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    529
  4. goog
    Replies:
    0
    Views:
    510
  5. GIMME
    Replies:
    3
    Views:
    11,973
    vforvikash
    Dec 29, 2008
Loading...

Share This Page