if test="not(descendant::*[name()=name(current())] | following::*[name()=name(current())])" : following « 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 » following 
4. 9. 1. if test="not(descendant::*[name()=name(current())] | following::*[name()=name(current())])"
File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<data>
    <AAA>
      <BBB id="b1">
        <CCC name="q" size="12"/>
        <EEE id="e1">
          <SSS/>
        </EEE>
        <CCC weight="45"/>
        <CCC/>
      </BBB>
    </AAA>
    <AAA>
      <EEE id="e2"/>
      <CCC>
        <DDD/>
        <DDD/>
      </CCC>
    </AAA>
</data>
File: Transform.xslt

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

    <xsl:template match="/">
      <TABLE border="1" width="90%">
        <xsl:apply-templates select="//*"/>
      </TABLE>
    </xsl:template>
    <xsl:template match="*">
      <xsl:if test="not(descendant::*[name()=name(current())] | following::*[name()=name(current())])">
        <TR>
          <TD>
            <xsl:value-of select="name()"/>
          </TD>
          <TD>
            <xsl:apply-templates select="." mode="list"/>
          </TD>
        </TR>
      </xsl:if>
    </xsl:template>
    <xsl:template match="*" mode="list">
      <xsl:for-each select="//*[name()=name(current())]/*">
        <xsl:value-of select="name()"/>
      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>  

Output:

<?xml version="1.0" encoding="UTF-8"?><TABLE border="1" width="90%"><TR><TD>data</TD><TD>AAAAAA</TD></TR><TR><TD>BBB</TD><TD>CCCEEECCCCCC</TD></TR><TR><TD>SSS</TD><TD/></TR><TR><TD>AAA</TD><TD>BBBEEECCC</TD></TR><TR><TD>EEE</TD><TD>SSS</TD></TR><TR><TD>CCC</TD><TD>DDDDDD</TD></TR><TR><TD>DDD</TD><TD/></TR></TABLE>
4. 9. following
4. 9. 1. if test="not(descendant::*[name()=name(current())] | following::*[name()=name(current())])"
4. 9. 2. following axis contains all nodes that come after the context node, but excludes all descendant nodes.
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.