Skip Headers

Oracle9i XML Database Developer's Guide - Oracle XML DB
Release 2 (9.2)

Part Number A96620-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

D
XSLT Primer

This appendix describes introductory information about the W3C XSL and XSLT Recommendation. It contains the following sections:

Introducing XSL

XML documents have structure but no format. Extensible Stylesheet Language (XSL) adds formatting to XML documents. It provides a way to display XML semantics and can map XML elements into other formatting languages such as HTML.

See Also:

The W3C XSL Transformation Recommendation Version 1.0

This specification defines the syntax and semantics of XSLT, which is a language for transforming XML documents into other XML documents.

XSLT is designed for use as part of XSL, which is a stylesheet language for XML. In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.

XSLT is also designed to be used independently of XSL. However, XSLT is not intended as a completely general-purpose XML transformation language. Rather it is designed primarily for the kinds of transformations that are needed when XSLT is used as part of XSL.

See Also:

http://www.w3.org/TR/xslt

This specification defines the syntax and semantics of the XSLT language. A transformation in the XSLT language is expressed as a well-formed XML document conforming to the Namespaces in XML Recommendation, which may include both elements that are defined by XSLT and elements that are not defined by XSLT.

XSLT-defined elements are distinguished by belonging to a specific XML namespace (see [2.1 XSLT Namespace]), which is referred to in this specification as the XSLT namespace. Thus this specification is a definition of the syntax and semantics of the XSLT namespace.

A transformation expressed in XSLT describes rules for transforming a source tree into a result tree. The transformation is achieved by associating patterns with templates. A pattern is matched against elements in the source tree. A template is instantiated to create part of the result tree. The result tree is separate from the source tree. The structure of the result tree can be completely different from the structure of the source tree. In constructing the result tree, elements from the source tree can be filtered and reordered, and arbitrary structure can be added.

A transformation expressed in XSLT is called a stylesheet. This is because, in the case when XSLT is transforming into the XSL formatting vocabulary, the transformation functions as a stylesheet.

This document does not specify how an XSLT stylesheet is associated with an XML document. It is recommended that XSL processors support the mechanism described in. When this or any other mechanism yields a sequence of more than one XSLT stylesheet to be applied simultaneously to a XML document, then the effect should be the same as applying a single stylesheet that imports each member of the sequence in order.

A stylesheet contains a set of template rules. A template rule has two parts: a pattern which is matched against nodes in the source tree and a template which can be instantiated to form part of the result tree. This allows a stylesheet to be applicable to a wide class of documents that have similar source tree structures.

The W3C is developing the XSL specification as part of its Style Sheets Activity. XSL has document manipulation capabilities beyond styling. It is a stylesheet language for XML.

The July 1999 W3C XSL specification, was split into two separate documents:

The formatting objects used in XSL are based on prior work on Cascading Style Sheets (CSS) and the Document Style Semantics & Specification Language (DSSSL). XSL is designed to be easier to use than DSSSL.

Capabilities provided by XSL as defined in the proposal enable the following functionality:

XSL Specification Proposal

The XSL specification defines XSL as a language for expressing stylesheets. Given a class of arbitrarily structured XML documents or data files, designers use an XSL stylesheet to express their intentions about how that structured content should be presented; that is, how the source content should be styled, laid out, and paginated in a presentation medium, such as a window in a Web browser or a hand-held device, or a set of physical pages in a catalog, report, pamphlet, or book. Formatting is enabled by including formatting semantics in the result tree.

Formatting semantics are expressed in terms of a catalog of classes of formatting objects. The nodes of the result tree are formatting objects. The classes of formatting objects denote typographic abstractions such as page, paragraph, table, and so forth.

Finer control over the presentation of these abstractions is provided by a set of formatting properties, such as those controlling indents, word and letter spacing, and widow, orphan, and hyphenation control. In XSL, the classes of formatting objects and formatting properties provide the vocabulary for expressing presentation intent.

An implementation is not mandated to provide these as separate processes. Furthermore, implementations are free to process the source document in any way that produces the same result as if it were processed using the conceptual XSL processing model.

Namespaces in XML

A namespace is a unique identifier or name. This is needed because XML documents can be authored separately with different DTDs or XML Schemas. Namespaces prevent conflicts in markup tags by identifying which DTD or XML Schema a tag comes from. Namespaces link an XML element to a specific DTD or XML Schema.

Before you can use a namespace marker such as rml:, xhtml:, or xsl:, you must identify it using the namespace indicator, xmlns as shown in the next paragraph.

See Also:

http://w3.org/TR/REC-xml-names

XSL Stylesheet Architecture

The XSL stylesheets must include the following syntax:

XSL Transformation (XSLT)

XSLT is designed to be used as part of XSL. In addition to XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an XML document by using XSLT to describe how the document is transformed into another XML document that uses the formatting vocabulary.

Meanwhile the second part is concerned with the XSL formatting objects, their attributes, and how they can be combined.

See Also:

Chapter 6, "Transforming and Validating XMLType Data"

XSLT 1.1 Specification

The W3C Working Group on XSL has released a document describing the requirements for the XSLT 1.1 specification. The primary goal of the XSLT 1.1 specification is to improve stylesheet portability. The new draft is available at http://www.w3.org/TR/xslt11req

In addition the XSLT 1.0 extension mechanism provides for an additional built-in transformation functionality.

Benefits of the extensions come at the price of portability. Since XSLT 1.0 provides no details or guidance on the implementation of extensions, today any user-written or built-in extensions are inevitably tied to a single XSLT processor.

Goal 1. Improve Stylesheet Portability

The primary goal of the XSLT 1.1 specification is to improve stylesheet portability. This goal will be achieved by standardizing the mechanism for implementing extension functions, and by including in the core XSLT specification two of the built-in extensions that many existing vendors XSLT processors have added due to user demand:

Goal 2. Support the New XML Specification

A secondary goal of the XSLT 1.1 specification is to support the new XML base specification.

The XSLT 1.1 specification proposal provides the requirements that will achieve these goals. The working group has decided to limit the scope of XSLT 1.1 to the standardization of features already implemented in several XSLT 1.0 processors, and concentrate first on standardizing the implementation of extension functions.

Standardization of extension elements and support for new XML Schema data type aware facilities are planned for XSLT 2.0.

XML Path Language (Xpath)

A separate, related specification is published as the XML Path Language (XPath) Version 1.0. XPath is a language for addressing parts of an XML document, essential for cases where you want to specify exactly which parts of a document are to be transformed by XSL. For example, XPath lets you select all paragraphs belonging to the chapter element, or select the elements called special notes. XPath is designed to be used by both XSLT and XPointer. XPath is the result of an effort to provide a common syntax and semantics for functionality shared between XSL transformations and XPointer.

See Also:

Appendix C, "XPath and Namespace Primer"

CSS Versus XSL

W3C is working to ensure that interoperable implementations of the formatting model is available.

Cascading Stylesheets (CSS)

Cascading Stylesheets (CSS) can be used to style HTML documents. CSS were developed by the W3C Style Working Group. CSS2 is a style sheet language that allows authors and users to attach styles (for example, fonts, spacing, or aural cues) to structured documents, such as HTML documents and XML applications.

By separating the presentation style of documents from the content of documents, CSS2 simplifies Web authoring and site maintenance.

XSL

XSL, on the other hand, is able to transform documents. For example, XSL can be used to transform XML data into HTML/CSS documents on the Web server. This way, the two languages complement each other and can be used together. Both languages can be used to style XML documents. CSS and XSL will use the same underlying formatting model and designers will therefore have access to the same formatting features in both languages.

The model used by XSL for rendering documents on the screen builds on years of work on a complex ISO-standard style language called DSSSL. Aimed mainly at complex documentation projects, XSL also has many uses in automatic generation of tables of contents, indexes, reports, and other more complex publishing tasks.

XSL Stylesheet Example, PurchaseOrder.xsl

The following example, PurchaseOrder.xsl, is an example of an XSL stylesheet. the example stylesheet is used in the examples in Chapter 3, "Using Oracle XML DB".

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:xdb="http://xmlns.oracle.com/xdb" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <xsl:template match="/">
    <html>
      <head/>
      <body bgcolor="#003333" text="#FFFFCC" link="#FFCC00"             
            vlink="#66CC99" alink="#669999">
        <FONT FACE="Arial, Helvetica, sans-serif">
          <xsl:for-each select="PurchaseOrder"/>
          <xsl:for-each select="PurchaseOrder">
            <center>
              <span style="font-family:Arial; font-weight:bold">
                <FONT COLOR="#FF0000">
                  <B>Purchase Order </B>
                </FONT>
              </span>
            </center>
            <br/>
            <center>
              <xsl:for-each select="Reference">
                <span style="font-family:Arial; font-weight:bold">
                  <xsl:apply-templates/>
                </span>
              </xsl:for-each>
            </center>
          </xsl:for-each>
          <P>
            <xsl:for-each select="PurchaseOrder">
              <br/>
            </xsl:for-each>
            <P/>
            <P>
              <xsl:for-each select="PurchaseOrder">
                <br/>
              </xsl:for-each>
            </P>
          </P>
          <xsl:for-each select="PurchaseOrder"/>
          <xsl:for-each select="PurchaseOrder">
            <table border="0" width="100%" BGCOLOR="#000000">
              <tbody>
                <tr>
                  <td WIDTH="296">
                    <P>
                      <B>
                        <FONT SIZE="+1" COLOR="#FF0000" 
                         FACE="Arial, Helvetica, sans-serif">Internal
                        </FONT>
                      </B>
                    </P>
                    <table border="0" width="98%" BGCOLOR="#000099">
                      <tbody>
                        <tr>
                          <td WIDTH="49%">
                            <B>
                              <FONT COLOR="#FFFF00">Actions</FONT>
                            </B>
                          </td>
                          <td WIDTH="51%">
                            <xsl:for-each select="Actions">
                              <xsl:for-each select="Action">
                                <table border="1" WIDTH="143">
                                  <xsl:if test="position()=1">
                                    <thead>
                                      <tr>
                                        <td HEIGHT="21">
                                          <FONT  
                                           COLOR="#FFFF00">User</FONT>
                                        </td>
                                        <td HEIGHT="21">
                                          <FONT
                                           COLOR="#FFFF00">Date</FONT>
                                        </td>
                                      </tr>
                                    </thead>
                                  </xsl:if>
                                  <tbody>
                                    <tr>
                                      <td>
                                        <xsl:for-each select="User">
                                          <xsl:apply-templates/>
                                        </xsl:for-each>
                                      </td>
                                      <td>
                                        <xsl:for-each select="Date">
                                          <xsl:apply-templates/>
                                        </xsl:for-each>
                                      </td>
                                    </tr>
                                  </tbody>
                                </table>
                              </xsl:for-each>
                            </xsl:for-each>
                          </td>
                        </tr>
                        <tr>
                          <td WIDTH="49%">
                            <B>
                              <FONT COLOR="#FFFF00">Requestor</FONT>
                            </B>
                          </td>
                          <td WIDTH="51%">
                            <xsl:for-each select="Requestor">
                              <xsl:apply-templates/>
                            </xsl:for-each>
                          </td>
                        </tr>
                        <tr>
                          <td WIDTH="49%">
                            <B>
                              <FONT COLOR="#FFFF00">User</FONT>
                            </B>
                          </td>
                          <td WIDTH="51%">
                            <xsl:for-each select="User">
                              <xsl:apply-templates/>
                            </xsl:for-each>
                          </td>
                        </tr>
                        <tr>
                          <td WIDTH="49%">
                            <B>
                              <FONT COLOR="#FFFF00">Cost Center</FONT>
                            </B>
                          </td>
                          <td WIDTH="51%">
                            <xsl:for-each select="CostCenter">
                              <xsl:apply-templates/>
                            </xsl:for-each>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </td>
                  <td width="93"/>
                  <td valign="top" WIDTH="340">
                    <B>
                      <FONT COLOR="#FF0000">
                        <FONT SIZE="+1">Ship To</FONT>
                      </FONT>
                    </B>
                    <xsl:for-each select="ShippingInstructions">
                      <xsl:if test="position()=1"/>
                    </xsl:for-each>
                    <xsl:for-each select="ShippingInstructions">
                      <xsl:if test="position()=1">
                        <table border="0" BGCOLOR="#999900">
                          <tbody>
                            <tr>
                              <td WIDTH="126" HEIGHT="24">
                                <B>Name</B>
                              </td>
                              <xsl:for-each
                                   select="../ShippingInstructions">
                                <td WIDTH="218" HEIGHT="24">
                                  <xsl:for-each select="name">
                                    <xsl:apply-templates/>
                                  </xsl:for-each>
                                </td>
                              </xsl:for-each>
                            </tr>
                            <tr>
                              <td WIDTH="126" HEIGHT="34">
                                <B>Address</B>
                              </td>
                              <xsl:for-each 
                                   select="../ShippingInstructions">
                                <td WIDTH="218" HEIGHT="34">
                                  <xsl:for-each select="address">
                                    <span style="white-space:pre">
                                      <xsl:apply-templates/>
                                    </span>
                                  </xsl:for-each>
                                </td>
                              </xsl:for-each>
                            </tr>
                            <tr>
                              <td WIDTH="126" HEIGHT="32">
                                <B>Telephone</B>
                              </td>
                              <xsl:for-each  
                                   select="../ShippingInstructions">
                                <td WIDTH="218" HEIGHT="32">
                                  <xsl:for-each select="telephone">
                                    <xsl:apply-templates/>
                                  </xsl:for-each>
                                </td>
                              </xsl:for-each>
                            </tr>
                          </tbody>
                        </table>
                      </xsl:if>
                    </xsl:for-each>
                  </td>
                </tr>
              </tbody>
            </table>
            <br/>
            <B>
              <FONT COLOR="#FF0000" SIZE="+1">Items:</FONT>
            </B>
            <br/>
            <br/>
            <table border="0">
              <xsl:for-each select="LineItems">
                <xsl:for-each select="LineItem">
                  <xsl:if test="position()=1">
                    <thead>
                      <tr bgcolor="#C0C0C0">
                        <td>
                          <FONT COLOR="#FF0000">
                            <B>ItemNumber</B>
                          </FONT>
                        </td>
                        <td>
                          <FONT COLOR="#FF0000">
                            <B>Description</B>
                          </FONT>
                        </td>
                        <td>
                          <FONT COLOR="#FF0000">
                            <B>PartId</B>
                          </FONT>
                        </td>
                        <td>
                          <FONT COLOR="#FF0000">
                            <B>Quantity</B>
                          </FONT>
                        </td>
                        <td>
                          <FONT COLOR="#FF0000">
                            <B>Unit Price</B>
                          </FONT>
                        </td>
                        <td>
                          <FONT COLOR="#FF0000">
                            <B>Total Price</B>
                          </FONT>
                        </td>
                      </tr>
                    </thead>
                  </xsl:if>
                  <tbody>
                    <tr bgcolor="#DADADA">
                      <td>
                        <FONT COLOR="#000000">
                          <xsl:for-each select="@ItemNumber">
                            <xsl:value-of select="."/>
                          </xsl:for-each>
                        </FONT>
                      </td>
                      <td>
                        <FONT COLOR="#000000">
                          <xsl:for-each select="Description">
                            <xsl:apply-templates/>
                          </xsl:for-each>
                        </FONT>
                      </td>
                      <td>
                        <FONT COLOR="#000000">
                          <xsl:for-each select="Part">
                            <xsl:for-each select="@Id">
                              <xsl:value-of select="."/>
                            </xsl:for-each>
                          </xsl:for-each>
                        </FONT>
                      </td>
                      <td>
                        <FONT COLOR="#000000">
                          <xsl:for-each select="Part">
                            <xsl:for-each select="@Quantity">
                              <xsl:value-of select="."/>
                            </xsl:for-each>
                          </xsl:for-each>
                        </FONT>
                      </td>
                      <td>
                        <FONT COLOR="#000000">
                          <xsl:for-each select="Part">
                            <xsl:for-each select="@UnitPrice">
                              <xsl:value-of select="."/>
                            </xsl:for-each>
                          </xsl:for-each>
                        </FONT>
                      </td>
                      <td>
                        <FONT FACE="Arial, Helvetica, sans-serif" 
                              COLOR="#000000">
                          <xsl:for-each select="Part">
                            <xsl:value-of select="@Quantity*@UnitPrice"/>
                          </xsl:for-each>
                        </FONT>
                      </td>
                    </tr>
                  </tbody>
                </xsl:for-each>
              </xsl:for-each>
            </table>
          </xsl:for-each>
        </FONT>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>



Go to previous page Go to next page
Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback