Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the value of the current node

Tags:

xml

xslt

xpath

I'm not overly familiar with the terminology, so I'm not even sure the title of the question is accurate but I shall try to explain best I can.

I have the below XML example.

<countries>
  <country name="Afghanistan" population="22664136" area="647500">
    <language percentage="11">Turkic</language>
    <language percentage="35">Pashtu</language>
    <language percentage="50">Afghan Persian</language>
  </country>
</countries>

I use XPath down to the language nodes (/countries/country/ and then a for-each for the languages).

<language percentage="11">Turkic</language>

Using XSLT how can I output the value of , in the above example "Turkic". I can't think of another way to phrase the question but its like I am at the node and don't know the syntax to grab the value of this node.

Thanks in advance

like image 440
Aleski Avatar asked Aug 04 '14 07:08

Aleski


1 Answers

The xsl:value-of element and current() function should do the trick:

<xsl:value-of select="current()"/>

I don't know the exact structure of your template, but for instance the following one outputs the language names:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/countries">
    <xsl:for-each select="country">
      <xsl:value-of select="current()"/>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
like image 171
joergl Avatar answered Sep 27 '22 19:09

joergl