Shoaib Nawaz
Shoaib Nawaz

Reputation: 2320

XSL: How to print an iterated node in for-each

xml:

<skills>
  <skill>PHP</skill>
  <skill>CSS</skill>
  <skill>HTML</skill>
  <skill>XML</skill>
</skills>

XSL:

<ul>
  <xsl:for-each select="skills/skill">
    <li><xsl:value-of select="[what should be xpath here]" /></li
  </xsl:for-each>
</ul>

Here what should be the xpath to print each skill?

Upvotes: 1

Views: 3481

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243529

Use: .

The . abbreviation is equivalent to self::node() and means: the current node.

<xsl:value-of select="someNode"/>

outputs the string value of the node, which in your case is the value of only text node of the skills/skill node that is currently selected by the <xsl:for-each> instruction.

Upvotes: 1

Abdel Raoof Olakara
Abdel Raoof Olakara

Reputation: 19353

You can get the values of skill tags as follows:

<xsl:for-each select="skills/skill">
<li><xsl:value-of select="." /></li>
</xsl:for-each>

Upvotes: 6

Related Questions