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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top