Don't output text nodes unless explicitly told to : parent « 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 » parent 
Don't output text nodes unless explicitly told to


File: Data.xml

<wine grape="A">
  <winery>shop 1</winery>
  <product>product 1</product>
  <year>1998</year>
  <desc>description</desc>
  <prices>
    <list>6.99</list>
    <discounted>5.99</discounted>
    <case>71.50</case>
  </prices>
</wine>


File: Transform.xslt

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

  <xsl:template match="text()" />
  <xsl:template match="list">
    ~~~~ Start of list element's template ~~~~ 1. List price
    (current node){
    <xsl:apply-templates />
    2. Parent element (pricescontents: {
    <xsl:value-of select=".." />
    3. Grandparent element contents: {
    <xsl:value-of select="../.." />
    4. Attribute of grandparent: {
    <xsl:value-of select="../../@grape" />
    5. Sibling node {
    <xsl:value-of select="../discounted" />
    6. Uncle node {
    <xsl:value-of select="../../product" />
    7. Parent node's name: {
    <xsl:value-of select="name(..)" />
    8. Grandparent node's name: {
    <xsl:value-of select="name(../..)" />
    ~~~~ End of list element's template ~~~~
  </xsl:template>
  

</xsl:stylesheet>

Output:


    ~~~~ Start of list element's template ~~~~ 1. List price
    (current node){
    
    2. Parent element (pricescontents: {
    
    6.99
    5.99
    71.50
  
    3. Grandparent element contents: {
    
  shop 1
  product 1
  1998
  description
  
    6.99
    5.99
    71.50
  

    4. Attribute of grandparent: {
    A
    5. Sibling node {
    5.99
    6. Uncle node {
    product 1
    7. Parent node's name: {
    prices
    8. Grandparent node's name: {
    wine
    ~~~~ End of list element's template ~~~~
  

 
Related examples in the same category
1. Use .. to indicate level
2. Get sibling with ../
3. Select element out of parent tag
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.