wrong XPath expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastian Kerekes

    #1

    wrong XPath expression

    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
  • Kenneth Stephen

    #2
    Re: wrong XPath expression

    Sebastian Kerekes wrote:
    [color=blue]
    > 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>
    >[/color]
    Sebastian,

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

    Regards,
    Kenneth

    Comment

    • Patrick TJ McPhee

      #3
      Re: wrong XPath expression

      In article <1095094072.466 925@newsmaster-03.atnet.at>,
      Sebastian Kerekes <sebastian.kere kes@gmx.net> 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
      ptjm@interlog.c om

      Comment

      Working...