XML - Level I Basic

nostalgicisolatedSoftware and s/w Development

Nov 4, 2013 (3 years and 7 months ago)

50 views

Unit 6
-

XML Transformations

www.profburnett.com

XML
-

Level I
Basic

Unit 6
-

XML
Transformations

Unit objectives


Identify the need to transform XML data, and
common transformation methods


Transform an XML document to HTML, apply
conditional statements, and change XML
grammar by using XSLT

7/14/2013

Copyright © Carl M. Burnett

2

Topic A


Topic A: Transforming XML documents


Topic B:
Data transformation

7/14/2013

3

Copyright © Carl M. Burnett

Transforming XML documents


First phase


Structural transformation


Data is converted from the structure of the incoming XML to
the structure of the desired output


Second phase


Formatting transformation


New structure is changed to the desired format like HTML,
PDF, DB2, Oracle, etc.

7/14/2013

Copyright © Carl M. Burnett

4

Transformation process

7/14/2013

Copyright © Carl M. Burnett

5

Need to transform XML data


XML is rarely used in its raw, original form


For XML data to be exchanged, displayed, and
put to effective use, it must be transformed into
another format


Most common application is converting XML to HTML
format

7/14/2013

Copyright © Carl M. Burnett

6

Transforming XML data


By using XML,
XSLT and
Xpath



XSL
developed into a platform
-

and multimedia
-
independent formatting language


A formatting language


Set of XML documents describing part of page media (i.e.,
tables, headers, and footnotes)


Transformation language



Convert into a result tree, consisting of the XSL formatting
objects

7/14/2013

Copyright © Carl M. Burnett

7

XSL evolution

XSL evolved into three XML languages


XSL: XML vocabulary


For specifying formatting objectives


XSL Transformation (XSLT)


Language for transforming XML documents


XML Path language (XPath)


An expression language used to ask or refer to part
of an XML document

7/14/2013

Copyright © Carl M. Burnett

8

XSL


Language for expressing stylesheets


A file describes how to display an XML document


Advanced stylesheet features


Formatting objects and attributes

7/14/2013

Copyright © Carl M. Burnett

9

XLST


Simple scripting language


For transforming one XML document into another


Based on template rules


Specifies how XML documents should be processed

7/14/2013

Copyright © Carl M. Burnett

10

Topic B


Topic A: Transforming XML documents


Topic B: Data transformation

7/14/2013

11

Copyright © Carl M. Burnett

The transformation process


The XML parser


Locates a DTD or schema within the XML document
and an XSLT stylesheet


Validates the XML document and XSLT stylesheet


Passes it to the XSL parser


Uses the XSLT stylesheet to transform and generate the
appropriate result tree document

7/14/2013

Copyright © Carl M. Burnett

12

Basic XML/XSL parsing

7/14/2013

Copyright © Carl M. Burnett

13

XML source document



Root element is named <CONTACTS>


Contains nine child elements, five contacts in sales


Locator attribute
-

provides information to processor
about remote resources


Psuedo
-
attributes
-

describe certain properties
mentioned in declaration but not any properties of the
element

7/14/2013

Copyright © Carl M. Burnett

14

Contacts XML document



Empty <HEAD
>
element




Locator attribute



7/14/2013

Copyright © Carl M. Burnett

15

XSLT Style Sheet Declarations

7/14/2013

16

Copyright © Carl M. Burnett

Student Exercise


Topic B
-

Data
Transformation


B
-
1:
Transforming an XML document to HTML
using XSLT


7/14/2013

17

Copyright © Carl M. Burnett

Unit summary


Learned how to identify the need for data
transformation, and common transformation
methods


Learned how to transform an XML document to
HTML, apply conditional statements, and
change XML grammar by using XSLT


7/14/2013

Copyright © Carl M. Burnett

18