XSL for-each and value-of

11,643
<xsl:value-of select="."/>
Share:
11,643

Related videos on Youtube

Sandy Vanderbleek
Author by

Sandy Vanderbleek

Updated on April 16, 2022

Comments

  • Sandy Vanderbleek
    Sandy Vanderbleek about 2 years

    Given the xml:

    <element>text</element>
    ...
    <element>text</element>
    

    And xsl:

    <xsl:for-each select="element">
    ...
    </xsl:for-each>
    

    What do I need to put inside the for-each loop to access the text? There doesn't seem to be a corresponding xsl:value-of because select="", select="/", and select="element" are all wrong.

  • Sandy Vanderbleek
    Sandy Vanderbleek about 14 years
    also select="text()" as I just found in the xpath recommendation
  • Tomalak
    Tomalak about 14 years
    @Sandy The difference is this: . refers to the current node (<element>) itself. The value-of a node is its entire text contents (including the text of any descendant nodes!). text() only refers to the direct children of the current node that are text nodes (this excludes any descendant nodes!). In your case, this makes no actual difference. There are cases where it does.