Union matching : union « XSLT stylesheet « 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 » XSLT stylesheet » union 
5. 71. 1. Union matching
File: Data.xml

<?xml version="1.0" encoding="UTF-8"?>
<provinces>
 <province id="AB">
  <name>Alberta</name>
  <abbreviation>AB</abbreviation>
 </province>
 <province id="BC">
  <name>British Columbia</name>
  <abbreviation>BC</abbreviation>
 </province>

</provinces>

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:output method="html" />
  <xsl:output doctype-system="http://www.w3.org/TR/html4/strict.dtd" />
  <xsl:output doctype-public="-//W3C//DTD HTML 4.01//EN" />

  <xsl:template match="provinces">
    <html>
      <head>
        <title>Provinces of Canada and Abbreviations</title>
      </head>
      <body>
        <h3>
          Provinces of Canada and Abbreviations
        </h3>
        <table>
          <thead>
            <tr>
              <td>Province</th>
              <td>Abbreviation</th>
            </tr>
          </thead>
          <tbody align="center">
            <xsl:apply-templates select="province" />
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="province">
    <tr>
      <xsl:apply-templates select="name|abbreviation" />
    </tr>
  </xsl:template>

  <xsl:template match="name|abbreviation">
    <td>
      <xsl:apply-templates />
    </td>
  </xsl:template>

</xsl:stylesheet>

Output:

<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Provinces of Canada and Abbreviations</title>
   </head>
   <body>
      <h3>
                   Provinces of Canada and Abbreviations
                 
      </h3>
      <table>
         <thead>
            <tr>
               <td>Province</th>
               <td>Abbreviation</th>
            </tr>
         </thead>
         <tbody align="center">
            <tr>
               <td>Alberta</td>
               <td>AB</td>
            </tr>
            <tr>
               <td>British Columbia</td>
               <td>BC</td>
            </tr>
         </tbody>
      </table>
   </body>
</html>
5. 71. union
5. 71. 1. Union matching
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.