The self::
axis always locates the context node. It is often used to retrieve the value of the current node, particularly as the select
attribute of the <xsl:value-of>
element.
To display the name of each employee in the international division identified in the sample XML document as a level-2 heading, you could use a simple XSL template rule such as the XSLT file shown below.
XML File (orgchart.xml)
Use orgchart.xml (in Sample XML File for Navigating XPath Axes) and edit its href
attribute to refer to orgchart-self.xsl.
XSLT File (orgchart-self.xsl)
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- suppress text nodes not covered in subsequent template rule -->
<xsl:template match="text()"/>
<xsl:template match="president[division='International']">
<xsl:for-each select="descendant::name">
<h2><xsl:value-of select="self::*
"/></h2>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Formatted Output
Katie McAskill-White
Neil Charney
Beth Silverberg
Lani Ota
Peter Porzuczek
Marea Angela Castaneda