wrong XPath expression

S

Sebastian Kerekes

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
 
K

Kenneth Stephen

Sebastian said:
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
 
P

Patrick TJ McPhee

[...]

% <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.
 

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
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top