Selecting a Node's Parent or Siblings : parent « XPath « XML Tutorial






The .. is often combined with the attribute axis to find the attribute of the parent node (../@name).
You can use an asterisk as a wildcard within the path.
For example, /*/A would select all the A elements of all of the siblings of the current node.


File: Data.xml

<?xml version="1.0"?>
<employee>
  <name language="English">T1</name>
  <name language="Latin">T2</name>
  <projects>
    <project>project1</project>
    <project>destruction</project>
    <project>medicine</project>
  </projects>
  <weight>3 points</weight>
</employee>


File: Transform.xslt

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="projects">

    <ul>
      <xsl:value-of select="../name[@language='English']" />
      <xsl:for-each select="project">
        <li>
          <xsl:value-of select="." />
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
</xsl:stylesheet>


Output:
<?xml version="1.0" encoding="UTF-8"?>
  T1
  T2
  <ul>T1<li>project1</li><li>destruction</li><li>
      medicine 
    </li></ul>
  3 points








4.13.parent
4.13.1.returns the name of the parent element
4.13.2.The parent axis is used to select the parent node of the context node.
4.13.3.Selecting a Node's Parent or Siblings