Tài liệu Module 7: Formatting and Transforming: XSL and XSLT - Pdf 84

Contents
Overview 1
Lesson: Defining XSL 2
Lesson: Transforming XML Using XSLT 8
Lesson: XSLT in the Microsoft .NET
Framework 20
Lab 7: Creating and Editing XSLT in
FrontPage 2002 and Visual Studio .NET 25
Review 31

Module 7: Formatting
and Transforming: XSL
and XSLT
Information in this document, including URL and other Internet Web site references, is subject to
change without notice. Unless otherwise noted, the example companies, organizations, products,
domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious,
and no association with any real company, organization, product, domain name, e-mail address,
logo, person, places or events is intended or should be inferred. Complying with all applicable
copyright laws is the responsibility of the user. Without limiting the rights under copyright, no

not time to explore most of these features and capabilities in this module. The
aim of this module is to provide an introduction to XSLT without completely
overwhelming the participants. Emphasize at the outset that XSLT is the subject
of an entire five-day course, Course 1913A, Exchanging and Transforming
Data Using XML and XSLT.
This is not an easy topic to do well. Teaching this module without preparation
will make participants confused about XSL and XSLT. Prepare thoroughly for
this topic.
After completing this module, participants will be able to:
!
Explain the relationship between XSL and XSLT.
!
Compare XSLT with Extensible Stylesheet Language Formatting Objects
(XSL-FO).
!
Explain the syntax of a basic XSLT style sheet.
!
Write a basic XSLT style sheet that transforms an XML document.

Materials and Preparation
This section provides the materials and preparation tasks that you need to teach
this module.
To teach this module, you need the following materials:
• Microsoft PowerPoint
®
file 2500A_07.ppt

To prepare for this module:
!
Read all of the materials for this module.

relationship between XSL and its subset languages: XPath, XSLT and
XSL-FO. Explain why XSLT was developed. You will present an overview
of XSL and present a simple example of a style sheet based on the working
draft of XSL that applies formatting to XML.
!
Transforming XML Using XSLT
In this lesson, start by discussing the power of XSLT and the many ways
that you can use it. You may want to bring extra examples to this section,
but be mindful of the timing. You will present an overview of XSLT and
present a simple example of a style sheet that transforms XML.
!
XSLT in the Microsoft .NET Framework
The goal of this lesson is to describe the nature of XSLT support in the
.NET Framework and the particular role of the XslTransform class in the
“System.Xml.Xsl” namespace. Read as thoroughly as you can about this
topic. Search for the word “xlst” in the .NET Framework SDK.
Familiarize yourself with the ways in which XslTransform works with
other parts of the .NET Framework and its classes so that you can explain
the diagram in this lesson adequately.
Ensure that you teach this topic as an overview, because the details about
many of the methods, classes, and components might overwhelm
participants. Stress that there is significant documentation on this topic and
that there is extensive and diverse support in the .NET Framework for
XSLT. If you have time, you may wish to explain the concepts of the
XmlReader and XmlWriter classes further, but be sure not to go into too
much detail.
Finally, point your participants to other courses that cover this topic in
more detail.

Module 7: Formatting and Transforming: XSL and XSLT 1


To monitor the development of W3C activity regarding XSL and XSLT,
go to the XSL page at the XSLT page at
and the XSL working group page at

For more information about XSLT, see Course 1913A, Exchanging and
Transforming Data Using XML and XSLT.
You can apply the principles that you learn in Course 1913A to
Microsoft
®
.NET languages (Microsoft Visual Basic
®
.NET and Microsoft
Visual C#

.NET), but the specific syntax and methods used with the XSLT
syntax is different.

Introduction
Objectives
Note
2 Module 7: Formatting and Transforming: XSL and XSLT Lesson: Defining XSL
!
What Is XSL?
!
XSL Style Sheets



What Is XSL?
!
Extensible Stylesheet Language (XSL) never achieved W3C
Recommendation status
!
XSL branched:
"
XSLT is the style sheet language
"
XSL-FO is the formatting language
"
XPath is the language for specifying locations
XPath
XSL W3C Recommendations
XSL-FO
Formatting Objects
XSL-FO
Formatting Objects
XSLT
XSL Transformations

*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
XSL is an W3C initiative to develop a programming language for creating style
sheets. Here are some situations where you can use style sheets:
!


As work progressed on XSL, it became clear that the job or transforming XML
would require more than a single language. All further work on transforming
the XML structure became XSL Transformations (XSLT). Concurrent with the
work on XSLT was work on XPath. XPath is now hardly identified outside of
W3C documentation as being part of XSL because it has become so integral to
other XML technologies. But it was developed in the context of the W3C XSL
initiative. XSL-FO has achieved Recommendation status as of October 2001.
Here is a summary of the three languages that have come out of the W3C XSL
initiative.
XSL Subset
Language

Purpose

File extensions associated with use

XSLT Transform XML .xsl, .xml
XPath Specify paths and
locations in XML
XPath statements do not exist in stand-
alone files. XPath statements are
embedded within statements belonging to
other programming languages.
XSL-FO Express formatting
semantics
.xsl, .xml

The original vision of XSL was to divide the task of language development into
one part that transforms XML and another that formats XML. XSLT is now the

XSL is no longer supported by XML Core Services
!
Current development should use XSLT
<xsl:stylesheet xmlns:xsl=" /><xsl:stylesheet xmlns:xsl=" /><xsl:stylesheet xmlns:xsl=" /><xsl:stylesheet xmlns:xsl=" />Embedded XML Fra
gment
XSL Stylesheet

*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
You may encounter style sheets that use the obsolete XSL working draft
Uniform Resource Identifier (URI) in the namespace declaration. This
namespace sends a signal to the XML processor to process all elements that
are prefixed by xsl: by using special functionality of the processor that
transforms XML.
The Microsoft XML Parser (MSXML) version 3.0 still recognizes the XSL
namespace as a valid way to signify a style sheet. MSXML 3.0 is installed by
default by the Microsoft Windows
®
XP operating system and by Microsoft
Internet Explorer version 6.0. Therefore, for most projects, you can still use the
XSL URI in a style sheet namespace declaration.
However, the latest version of the Microsoft XML processor, Microsoft XML
Core Services (MSXML) version 4.0, does not recognize the XSL URI as a
valid way to signify a style sheet. Style sheets generated for new development
projects should use the XSLT URI. XSLT has reached W3C Recommendation
status. XSLT provides all of the functionality of XSL and more.
XSL style sheet

</xsl:template>

<xsl:template match="pet">
<pet>
<name><xsl:apply-templates select="name"/></name>
<breed><xsl:apply-templates select="breed"/></breed>
<weight><xsl:apply-templates
select="weight"/></weight>
</pet>
</xsl:template>

<xsl:template match="name">
<xsl:value-of />
</xsl:template>

<xsl:template match="breed">
<xsl:value-of />
</xsl:template>

<xsl:template match="weight">
<xsl:value-of />
</xsl:template>
</xsl:stylesheet>

Example
Module 7: Formatting and Transforming: XSL and XSLT 7 Demonstration: Formatting XML Using a Style Sheet
!

Introduction
8 Module 7: Formatting and Transforming: XSL and XSLT Lesson: Transforming XML Using XSLT
!
What Is XSLT?
!
Parts of an XSLT Style Sheet
!
What Can You Do with XSLT?

*****************************
ILLEGAL FOR NON
-
TRAINER USE
******************************
XSLT is the transformation language that is a core part of XSL. It provides the
mechanisms for transforming one XML structure into another.
An XSLT style sheet may itself be transformed by using another XSLT style
sheet. This is because XSLT style sheets are written in well-formed XML. The
fact that XSLT can also be modified makes it highly adaptable.
XSLT is also designed by the W3C to be used independently of XSL.
After completing this lesson, you will be able to describe:
!
The types of transformations that can be done with XSLT.
!
Ways in which you can use XSLT in a project that uses XML data.
!
The parts of an XSLT style sheet.

-
TRAINER USE
******************************
W3C created XSLT to provide a transformation language that enables you to
manipulate XML documents. To manipulate XML documents, you use an
XPath expression to retrieve data from the node tree and then apply templates
and match metadata and data for specific transformations.
XSLT is the language that allows you to transform XML trees. Transformations
can involve creating new elements or attributes, doing calculations, filtering,
sorting, changing the structure of the node tree to a new form for an output
XML document, or any combination of these. XSLT version 1.0 is the basis
upon which W3C is creating even more sophisticated transformation
capabilities.
XPath expressions provide XSLT with the semantics for identifying and
manipulating nodes in an XML tree. XSLT statements, called templates, match
certain patterns of elements or attributes. Templates contain XPath location
paths. XSLT uses XPath to match patterns of XML data and metadata in the
XML source.
Although the emphasis on XSLT is often on its transformation capabilities,
when it is used in conjunction with XPath expressions, it is extremely powerful
for selectively finding information wherever it appears in an XML document.
By using templates and various matching and selection methods, XSLT can
efficiently locate and select information from a very mixed XML document,
retrieve the data and the metadata, and produce different output documents.
An example of this is a compound business document from one government
agency that must be split into two or more simple documents for use by another
government agency.
Another example is an XML scientific data document that contains both
biological and chemical information from a research lab. When received by a
genetic engineering organization, the document must be split into a separate


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status