tags:

views:

14

answers:

2

If I have an XML file that includes

<param name="foo" value="5000" >foo is a way of making pasta sauce</param>
<param name="bar" value="3000" >bar is controlling the beer taps</param>

and I want to use XSLT to process this into an HTML file, with the name and value attributes and the text as a description, how can I get the XML node text?

<xsl:for-each select="param">
   <tr>
      <td><xsl:value-of select="@name"/></td>
      <td><xsl:value-of select="@value"/></td>
      <td><xsl:text> </xsl:text></td>
   </tr>
</xsl:for-each>

The above XSLT fragment does successfully get the name and value attributes, but it fails to get the text, and I think I'm missing something obvious but I don't know what.

+1  A: 

Try this

<xsl:for-each select="param">
   <tr>
      <td><xsl:value-of select="@name"/></td>
      <td><xsl:value-of select="@value"/></td>
      <td><xsl:value-of select="text()"/></td>
   </tr>
</xsl:for-each>
YoK
that works, thanks!
Jason S
@Jason S you also need to increase your accept rate ;)
YoK
:shrug: accepted 'cause it works + you had a ";)" in your comment... imho people expect both too quick of an answer acceptance + more of an acceptance rate. a lot of the questions I've asked are difficult / specific + I haven't gotten an answer that works well.
Jason S
:) thanks .....
YoK
A: 

aha, this also seems to work:

<xsl:for-each select="param">
   <tr>
      <td><xsl:value-of select="@name"/></td>
      <td><xsl:value-of select="@value"/></td>
      <td><xsl:value-of select="."/></td>
   </tr>
</xsl:for-each>
Jason S
@Jason S: Yes. And the diference is: `xsl:value-of select="text()"` output the string value of the first text node child, and `xsl:value-of select="."` output the context node' string value.
Alejandro