copy-of copies everything : copy of « 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 » copy of 
5. 47. 2. copy-of copies everything
File: Data.xml
<?xml version="1.0"?>
<results group="A">
  <match>
    <date>10-Jun-98</date>
    <team score="2">team 1</team>
    <team score="1">team 2</team>
  </match>
  <match>
    <date>10-Jun-98</date>
    <team score="2">team 3</team>
    <team score="2">team 4</team>
  </match>
</results>

File: Transform.xslt
<?xml version="1.0"?>

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

  <xsl:variable name="table-heading">
    <tr>
      <td>
        <b>Date</b>
      </td>
      <td>
        <b>Home Team</b>
      </td>
      <td>
        <b>Away Team</b>
      </td>
      <td>
        <b>Result</b>
      </td>
    </tr>
  </xsl:variable>

  <xsl:template match="/">
    <html>
      <body>
        <h1>
          Matches in Group
          <xsl:value-of select="/*/@group" />
        </h1>
        <xsl:for-each select="//match">
          <h2>
            <xsl:value-of
              select="concat(team[1], ' versus ', team[2])" />
          </h2>
          <table bgcolor="#cccccc" border="1"
            cellpadding="5">
            <xsl:copy-of select="$table-heading" />
            <tr>
              <td>
                <xsl:value-of select="date" />
                &#xa0;
              </td>
              <td>
                <xsl:value-of select="team[1]" />
                &#xa0;
              </td>
              <td>
                <xsl:value-of select="team[2]" />
                &#xa0;
              </td>
              <td>
                <xsl:value-of
                  select="concat(team[1]/@score, '-', team[2]/@score)" />
                &#xa0;
              </td>
            </tr>
          </table>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

Output:

<html>
   <body>
      <h1>
                   Matches in Group
                   A
      </h1>
      <h2>team versus team 2</h2>
      <table bgcolor="#cccccc" border="1" cellpadding="5">
         <tr>
            <td><b>Date</b></td>
            <td><b>Home Team</b></td>
            <td><b>Away Team</b></td>
            <td><b>Result</b></td>
         </tr>
         <tr>
            <td>10-Jun-98
                               &nbsp;
                             
            </td>
            <td>team 1
                               &nbsp;
                             
            </td>
            <td>team 2
                               &nbsp;
                             
            </td>
            <td>2-1
                               &nbsp;
                             
            </td>
         </tr>
      </table>
      <h2>team versus team 4</h2>
      <table bgcolor="#cccccc" border="1" cellpadding="5">
         <tr>
            <td><b>Date</b></td>
            <td><b>Home Team</b></td>
            <td><b>Away Team</b></td>
            <td><b>Result</b></td>
         </tr>
         <tr>
            <td>10-Jun-98
                               &nbsp;
                             
            </td>
            <td>team 3
                               &nbsp;
                             
            </td>
            <td>team 4
                               &nbsp;
                             
            </td>
            <td>2-2
                               &nbsp;
                             
            </td>
         </tr>
      </table>
   </body>
</html>
5. 47. copy of
5. 47. 1. 
5. 47. 2. copy-of copies everything
5. 47. 3. specify element to copy
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.