ancestor::node index : ancestor « XSLT stylesheet « XML

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
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 » XSLT stylesheet » ancestor 
ancestor::node index


File: Data.xml

<?xml-stylesheet type="text/xsl" href="Transform.xslt"?>
<orgchart date="28 March 2001">
  <person>
    <name>chart 1</name>
    <title>title1</title>
    <reports>
      <person>
        <name>a</name>
        <title>b</title>
        <reports>
          <person>
            <name>c</name>
            <title>d</title>
          </person>
          <person>
            <name>e</name>
            <title>f</title>
          </person>
        </reports>
      </person>
      <person>
        <name>S</name>
        <title>M</title>
      </person>
      <person>
        <name>S</name>
        <title>I</title>
      </person>
    </reports>
  </person>
</orgchart>
 

File: Transform.xslt

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

  <xsl:param name="title">Management Structure</xsl:param>

  <xsl:output indent="yes" />

  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:value-of select="$title" />
        </title>
      </head>
      <body>
        <h1>
          <xsl:value-of select="$title" />
        </h1>
        <p>
          The following responsibilies were announced on
          <xsl:value-of select="/orgchart/@date" />
          :
        </p>
        <table border="2" cellpadding="5">
          <tr>
            <th>Name</th>
            <th>Role</th>
            <th>Reporting to</th>
          </tr>
          <xsl:for-each select="//person">
            <tr>
              <td>
                <xsl:value-of select="name" />
              </td>
              <td>
                <xsl:value-of select="title" />
              </td>
              <td>
                <xsl:value-of
                  select="ancestor::person[1]/name" />
              </td>
            </tr>
          </xsl:for-each>
        </table>
        <hr />
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

Output:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Management Structure</title>
   </head>
   <body>
      <h1>Management Structure</h1>
      <p>
                   The following responsibilies were announced on
                   28 March 2001
                   :
                 
      </p>
      <table border="2" cellpadding="5">
         <tr>
            <th>Name</th>
            <th>Role</th>
            <th>Reporting to</th>
         </tr>
         <tr>
            <td>chart 1</td>
            <td>title1</td>
            <td></td>
         </tr>
         <tr>
            <td>a</td>
            <td>b</td>
            <td>chart 1</td>
         </tr>
         <tr>
            <td>c</td>
            <td>d</td>
            <td>a</td>
         </tr>
         <tr>
            <td>e</td>
            <td>f</td>
            <td>a</td>
         </tr>
         <tr>
            <td>S</td>
            <td>M</td>
            <td>chart 1</td>
         </tr>
         <tr>
            <td>S</td>
            <td>I</td>
            <td>chart 1</td>
         </tr>
      </table>
      <hr>
   </body>
</html>

 
Related examples in the same category
1. if test="ancestor::chapter"
2. Get value: $node/ancestor::node()
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.