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

XML Tutorial
1. Introduction
2. Namespace
3. XML Schema
4. XPath
5. XSLT stylesheet
Java
XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML Tutorial » XPath » parent 
4. 13. 3. Selecting a Node's Parent or Siblings
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
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.