descendant-or-self demo : descendant or self « 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 » descendant or self 
descendant-or-self demo



File: Data.xml

<chapter author="jm">
  <para>para1</para>
  <para author="ar">para2</para>
  <sect1 author="bd">
    <para>para3</para>
    <para>line 1</para>
    <sect2 author="jm">
      <para>line 2</para>
    </sect2>
  </sect1>
</chapter>

File: Transform.xslt


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

  <xsl:template match="chapter">
    <chapter>
      Authors
      <xsl:for-each select="descendant-or-self::*/@author">
        <xsl:value-of select="." />
        <xsl:text/>
      </xsl:for-each>
      <xsl:apply-templates />
    </chapter>
  </xsl:template>

</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?><chapter>
      Authors
      jmarbdjm
  para1
  para2
  
    para3
    line 1
    
      line 2
    
  
</chapter>

 
Related examples in the same category
1. select="descendant-or-self::*[@dept='programming']"
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.