wrong XPath expression

Discussion in 'XML' started by Sebastian Kerekes, Sep 13, 2004.

  1. Hi,

    executing this code ..

    <select name="language" class="v1">
    <xsl:for-each select="/document/select[@ref = 'language']/item">
    <option value="{value/text()}">
    <xsl:value-of select="text()"/>
    </option>
    </xsl:for-each>
    </select>

    ... results in this:

    <select class="v1" name="language">
    <option value="de"></option>
    <option value="en"></option>
    </select>

    Obviously <xsl:value-of select="text()"/> is wrong. I want to access the
    text of of the item-nodes. How can I solve that?

    Thx in advance,

    Sebastian
     
    Sebastian Kerekes, Sep 13, 2004
    #1
    1. Advertising

  2. Sebastian Kerekes wrote:

    > Hi,
    >
    > executing this code ..
    >
    > <select name="language" class="v1">
    > <xsl:for-each select="/document/select[@ref = 'language']/item">
    > <option value="{value/text()}">
    > <xsl:value-of select="text()"/>
    > </option>
    > </xsl:for-each>
    > </select>
    >

    Sebastian,

    What does the input XML fragment that you are running this on look like?

    Regards,
    Kenneth
     
    Kenneth Stephen, Sep 13, 2004
    #2
    1. Advertising

  3. In article <>,
    Sebastian Kerekes <> wrote:

    [...]

    % <xsl:value-of select="text()"/>

    This will retrieve the value of text nodes which are immediate
    children of the current node (in this case, the node being
    considered by the for-each).

    What you want to do is cast the current node to a string. As it
    happens, this is precisely what value-of does, so you could just
    use

    <xsl:value-of select="."/>

    but this explicit should also do what you want

    <xsl:value-of select="string(.)"/>

    In either case, the value that gets copied to the result tree is
    the concatenation of all text nodes which are descendents of the
    current node.
    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Sep 14, 2004
    #3
    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. KathyB
    Replies:
    0
    Views:
    597
    KathyB
    Jul 1, 2003
  2. Marvin_123456

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

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,034
    jan V
    Jul 29, 2005
  3. Alastair Cameron
    Replies:
    1
    Views:
    7,535
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  4. GIMME
    Replies:
    3
    Views:
    12,053
    vforvikash
    Dec 29, 2008
  5. steve bull
    Replies:
    7
    Views:
    399
    David Carlisle
    Jun 20, 2005
Loading...

Share This Page