Science Fair Projects Ideas - XSLT

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

XSL Transformations

(Redirected from XSLT)

XSL Transformations, or XSLT, is an XML-based scripting language used for transforming XML documents. It is the XML transformation language part of the XSL specification (the other parts being XSL-FO and XPath). As with XML and HTML, the XSLT specification is a Recommendation developed by the W3C.

To transform in this context means to apply an XSLT stylesheet to an XML document, stored as a source tree, so as to create a result tree. The result tree may be produced in XML, XHTML, HTML or any text-based format including plain text, tab- and comma-separated values, RTF and TeX. It may comprise text and markup from the XSLT stylesheet combined with parts of the incoming XML document, selected using XPath query-strings. Among many other options, the result tree may be written to an output file, transmitted over a network or simply displayed locally.

The language is declarative, i.e. an XSLT stylesheet consists of a collection of template rules which define the transformations to be performed. These template rules can be applied recursively.

The XSLT processor checks which template rules can be applied and executes the associated transformations based on a sequence of priorities.

An XSLT stylesheet is itself an XML document as the example below shows.

The W3C finalized the XSLT 1.0 specification in 1999 and the XSLT 2.0 specification currently has 'Working Draft' status.

Example

Example XSLT Stylesheet:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns="http://www.w3.org/1999/xhtml">
    <xsl:output method="xml" 
        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
    
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <title>test1</title>
                <style type="text/css">
                    h1          { padding: 10px; padding-width: 100%; background-color: silver }
                    td, th      { width: 40%; border: 1px solid silver; padding: 10px }
                    td:first-child, th:first-child  { width: 20% } 
                    table       { width: 650px }
                </style>
            </head>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="domains/*">
        <h1><xsl:value-of select="@ownedBy"/></h1>
        <p>The following host names are currently in use at <b><xsl:value-of select="local-name(.)"/></b></p>
        <table>
            <tr><th>Host name</th><th>URL</th><th>Used by</th></tr>
            <xsl:apply-templates/>
        </table>
    </xsl:template>
    
    <xsl:template match="host">
        <xsl:variable name="url" select="normalize-space(concat('http://', normalize-space(node()), '.', local-name(..)))"/>
        <tr>
            <td><xsl:value-of select="node()"/></td>
            <td><a href="{$url}"><xsl:value-of select="$url"/></a></td>
            <xsl:apply-templates select="use"/>
        </tr>
    </xsl:template>

    <xsl:template match="use">
        <td><xsl:value-of select="."/></td>
    </xsl:template>
        
</xsl:stylesheet> 

Example of incoming XML for above stylesheet:

<?xml version="1.0" encoding="UTF-8"?>

<domains>
    <sun.com ownedBy="Sun Microsystems Inc.">
        <host>
            www
            <use>World Wide Web site</use>
        </host>
        <host>
            java
            <use>Java info</use>
        </host>
    </sun.com>
    
    <w3.org ownedBy="The World Wide Web Consortium">
        <host>
            www
            <use>World Wide Web site</use>
        </host>
        <host>
            validator
            <use>web developers who want to get it right</use>
        </host>
    </w3.org>
</domains>

Output XHTML that this would produce:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type" /><title>test1</title><style type="text/css">
                    h1          { padding: 10px; padding-width: 100%; background-color: silver }
                    td, th      { width: 40%; border: 1px solid silver; padding: 10px }
                    td:first-child, th:first-child  { width: 20% } 
                    table       { width: 650px }
                </style></head><body>
    <h1>Sun Microsystems Inc.</h1><p>The following host names are currently in use at <b>sun.com</b></p><table><tr><th>Host name</th><th>URL</th><th>Used by</th></tr>
        <tr><td>
            www
            </td><td><a href="http://www.sun.com">http://www.sun.com</a></td><td>World Wide Web site</td></tr>
        <tr><td>
            java
            </td><td><a href="http://java.sun.com">http://java.sun.com</a></td><td>Java info</td></tr>
    </table>
    
    <h1>The World Wide Web Consortium</h1><p>The following host names are currently in use at <b>w3.org</b></p><table><tr><th>Host name</th><th>URL</th><th>Used by</th></tr>
        <tr><td>
            www
            </td><td><a href="http://www.w3.org">http://www.w3.org</a></td><td>World Wide Web site</td></tr>
        <tr><td>
            validator
            </td><td><a href="http://validator.w3.org">http://validator.w3.org</a></td><td>web developers who want to get it right</td></tr>
    </table>
    
</body></html>

See also

  • STX is intended as a high-speed, low memory consumption alternative to XSLT.
  • Smarty is a template engine written in PHP.

External links

  • Implementations for Java:
  • Implementations for C or C++:
  • Implementations for Python:
    • 4XSLT, in the 4Suite toolkit by Fourthought, Inc.
    • lxml by Martijn Faassen is a Pythonic wrapper of the libxslt C library
  • Implementations for specific operating systems:
    • Microsoft's MSXML library may be used in various Microsoft Windows application development environments and languages, such as .Net, Visual Basic, C, and JScript.
  • Implementations integrated into web browsers:

12-03-2008 10:22:39
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice