Title: XML, DTD, XML Schema, and XSLT
1XML, DTD, XML Schema, and XSLT
- Jianguo Lu
- University of Windsor
2Where we are
- XML
- DTD
- XML Schema
- XML Namespace
- XPath
- DOM Tree
- XSLT
3Name Conflict
lttablegt lttrgt lttdgtAppleslt/tdgt lttdgtBananaslt/tdgt
lt/trgtlt/tablegt
lttablegt ltnamegtAfrican Coffee Table lt/namegt ltwid
thgt80lt/widthgt ltlengthgt120lt/lengthgtlt/tablegt
- Solution add prefix to the tag names
lthtablegt lthtrgt lthtdgtAppleslt/htdgt lthtdgtBana
naslt/htdgt lt/htrgtlt/htablegt
ltftablegt ltfnamegtAfrican Coffee Table
lt/fnamegt ltfwidthgt80lt/fwidthgt ltflengthgt120lt/f
lengthgtlt/ftablegt
4Name spaces
HTML name space
Furniture name space
table
table
td
width
html
name
tr
price
body
th
length
height
5XML namespace
- An XML document may use more than one schema
- Since each structuring document was developed
independently, name clashes may appear - The solution is to use a different prefix for
each schema - prefixname
- ltprodproduct xmlnsprodhttp//example.org/prodgt
- ltprodnumbergt 557 lt/prodnumbergt
- ltprodsize systemUS-DRESSgt 10
lt/prodsizegt - lt/prodproductgt
6Namespace names
- Namespace names are URIs
- Many namespace names are in the form of HTTP URI.
- The purpose of a name space is not to point to a
location where a resource resides. - It is intended to provide a unique name that can
be associated with a particular organization. - The URI MAY point to a schema.
- ltprodproduct xmlnsprodhttp//example.org/prodgt
- ltprodnumbergt 557 lt/prodnumbergt
- ltprodsize systemUS-DRESSgt 10
lt/prodsizegt - lt/prodproductgt
7Namespace declaration
- A namespace is declared using an attribute starts
with xmlns. - You can declare multiple namespaces in one
instance. - ltordorder xmlnsordhttp//example.org/ord
- xmlnsprodhttp//example.org/prod
gt - ltordnumbergt 123ABC123lt/ordnumbergt
- ltprodproductgt
- ltprodnumbergt 557 lt/prodnumbergt
- ltprodsize systemUS-DRESSgt 10
lt/prodsizegt - lt/prodproductgt
- lt/ordordergt
8Default namespace declaration
- Default namespace maps unprefixed element type
name to a namespace. - ltorder xmlnshttp//example.org/ord
- xmlnsprodhttp//example.org/prod gt
- ltnumbergt 123ABC123 lt/numbergt
- ltprodproductgt
- ltprodnumbergt 557 lt/prodnumbergt
- ltprodsize systemUS-DRESSgt 10
lt/prodsizegt - lt/prodproductgt
- lt/ordergt
9Scope of namespace declaration
- Namespace declaration can appear in any start
tag. - The scope is in the element where it is declared.
- ltorder xmlnshttp//example.org/ordgt
- ltnumbergt 123ABC123 lt/numbergt
- ltprodproduct xmlnsprodhttp//example.org/pro
dgt - ltprodnumbergt 557 lt/prodnumbergt
- ltprodsize systemUS-DRESSgt 10
lt/prodsizegt - lt/prodproductgt
- lt/ordergt
10lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.book
s.org" xmlns"http//www.bo
oks.org"
elementFormDefault"qualified"gt ltxsdelement
name"BookStore"gt ltxsdcomplexTypegt
ltxsdsequencegt ltxsdelement
ref"Book" minOccurs"1" maxOccurs"unbounded"/gt
lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdelementgt
ltxsdelement name"Book"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement ref"Title" minOccurs"1"
maxOccurs"1"/gt ltxsdelement
ref"Author" minOccurs"1" maxOccurs"1"/gt
ltxsdelement ref"Date" minOccurs"1"
maxOccurs"1"/gt ltxsdelement
ref"ISBN" minOccurs"1" maxOccurs"1"/gt
ltxsdelement ref"Publisher" minOccurs"1"
maxOccurs"1"/gt lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdelementgt
ltxsdelement name"Title" type"xsdstring"/gt
ltxsdelement name"Author" type"xsdstring"/gt
ltxsdelement name"Date" type"xsdstring"/gt
ltxsdelement name"ISBN" type"xsdstring"/gt
ltxsdelement name"Publisher" type"xsdstring"/gt
lt/xsdschemagt
The elements and datatypes that are used to
construct schemas - schema - element -
complexType - sequence - string come from the
http///XMLSchema namespace
Indicates that the elements defined by this
schema - BookStore - Book - Title -
Author - Date - ISBN - Publisher are to go
in the http//www.books.org namespace
From Costello
11lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.books
.org" xmlns"http//www.book
s.org" elementFormDefault"q
ualified"gt ltxsdelement name"BookStore"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement ref"Book"
minOccurs"1" maxOccurs"unbounded"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt
lt/xsdelementgt ltxsdelement name"Book"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement ref"Title"
minOccurs"1" maxOccurs"1"/gt
ltxsdelement ref"Author" minOccurs"1"
maxOccurs"1"/gt ltxsdelement
ref"Date" minOccurs"1" maxOccurs"1"/gt
ltxsdelement ref"ISBN" minOccurs"1"
maxOccurs"1"/gt ltxsdelement
ref"Publisher" minOccurs"1" maxOccurs"1"/gt
lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdelementgt
ltxsdelement name"Title" type"xsdstring"/gt
ltxsdelement name"Author" type"xsdstring"/gt
ltxsdelement name"Date" type"xsdstring"/gt
ltxsdelement name"ISBN" type"xsdstring"/gt
ltxsdelement name"Publisher" type"xsdstring"/gt
lt/xsdschemagt
The default namespace is http//www.books.org whic
h is the targetNamespace!
This is referencing a Book element
declaration. The Book in what namespace? Since
there is no namespace qualifier it is referencing
the Book element in the default namespace, which
is the targetNamespace! Thus, this is a
reference to the Book element declaration in this
schema.
From Costello
12Import in XML Schema
- Now with the understanding of namespace, we can
introduce some more advanced features in XML
Schema. - The import element allows you to access elements
and types in a different namespace.
Namespace B
Namespace A
B.xsd
A.xsd
ltxsdschema gt ltxsdimport namespace"A"
schemaLocation"A.xsd"/gt
ltxsdimport namespace"B"
schemaLocation"B.xsd"/gt lt/xsdschemagt
C.xsd
13Example
Pentax.xsd
Nikon.xsd
Olympus.xsd
Camera.xsd
From Costello
14lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.nikon
.com" xmlns"http//www.niko
n.com" elementFormDefault"q
ualified"gt ltxsdcomplexType
name"body_type"gt ltxsdsequencegt
ltxsdelement name"description"
type"xsdstring"/gt lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdschemagt
Nikon.xsd
lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.olympus.com"
xmlns"http//www.olympus.com"
elementFormDefault"qualified"gt
ltxsdcomplexType name"lens_type"gt
ltxsdsequencegt ltxsdelement
name"zoom" type"xsdstring"/gt
ltxsdelement name"f-stop" type"xsdstring"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt lt/xsd
schemagt
Olympus.xsd
lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.pentax.com"
xmlns"http//www.pentax.com"
elementFormDefault"qualified"gt
ltxsdcomplexType name"manual_adapter_type"gt
ltxsdsequencegt ltxsdelement
name"speed" type"xsdstring"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt lt/xsdschem
agt
Pentax.xsd
From Costello
15lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.camer
a.org" xmlnsnikon"http//w
ww.nikon.com"
xmlnsolympus"http//www.olympus.com"
xmlnspentax"http//www.pentax.com"
elementFormDefault"qualified"
gt ltxsdimport namespace"http//www.nikon.com"
schemaLocation"Nikon.xsd"/gt
ltxsdimport namespace"http//www.olympus.com"
schemaLocation"Olympus.xsd"/gt
ltxsdimport namespace"http//www.pentax.com"
schemaLocation"Pentax.xsd"/gt
ltxsdelement name"camera"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement name"body"
type"nikonbody_type"/gt
ltxsdelement name"lens" type"olympuslens_type"/
gt ltxsdelement
name"manual_adapter
type"pentaxmanual_adapt
er_type"/gt lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdelementgt ltxsdschemagt
Here I am using the body_type that is defined in
the Nikon namespace
Camera.xsd
From Costello
16lt?xml version"1.0"?gt ltccamera
xmlnsc"http//www.camera.org"
xmlnsnikon"http//www.nikon.com"
xmlnsolympus"http//www.olympus.com"
xmlnspentaxhttp//www.pentax.com
ltcbodygt ltnikondescriptiongtErgonomically
designed casing for easy handling
lt/nikondescriptiongt lt/cbodygt ltclensgt
ltolympuszoomgt300mmlt/olympuszoomgt
ltolympusf-stopgt1.2lt/olympusf-stopgt
lt/clensgt ltcmanual_adaptergt
ltpentaxspeedgt1/10,000 sec to 100
seclt/pentaxspeedgt lt/cmanual_adaptergt lt/ccam
eragt
lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.olympus.com"
xmlns"http//www.olympus.com"
elementFormDefault"qualified"gt
ltxsdcomplexType name"lens_type"gt
ltxsdsequencegt ltxsdelement
name"zoom" type"xsdstring"/gt
ltxsdelement name"f-stop" type"xsdstring"/gt
lt/xsdsequencegt lt/xsdcomplexTypegt lt/xsd
schemagt
lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.nikon
.com" xmlns"http//www.niko
n.com" elementFormDefault"q
ualified"gt ltxsdcomplexType
name"body_type"gt ltxsdsequencegt
ltxsdelement name"description"
type"xsdstring"/gt lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdschemagt
Camera.xml
From Costello
17Include
- The include element allows you to access
components in other schemas - All the schemas you include must have the same
namespace as your schema (i.e., the schema that
is doing the include) - The net effect of include is as though you had
typed all the definitions directly into the
containing schema
LibraryEmployee.xsd
LibraryBook.xsd
ltxsdschema gt ltxsdinclude
schemaLocation"LibraryBook.xsd"/gt
ltxsdinclude schemaLocation"LibraryEmployee.xsd"/
gt lt/xsdschemagt
Library.xsd
From Costello
18lt?xml version"1.0"?gt ltxsdschema
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
targetNamespace"http//www.libra
ry.org" xmlns"http//www.li
brary.org"
elementFormDefault"qualified"gt ltxsdinclude
schemaLocation"LibraryBook.xsd"/gt
ltxsdinclude schemaLocation"LibraryEmployee.xsd"/
gt ltxsdelement name"Library"gt
ltxsdcomplexTypegt ltxsdsequencegt
ltxsdelement name"Books"gt
ltxsdcomplexTypegt
ltxsdsequencegt
ltxsdelement ref"Book" maxOccurs"unbounded"/gt
lt/xsdsequencegt
lt/xsdcomplexTypegt
lt/xsdelementgt ltxsdelement
name"Employees"gt
ltxsdcomplexTypegt
ltxsdsequencegt
ltxsdelement ref"Employee" maxOccurs"unbounded"/
gt lt/xsdsequencegt
lt/xsdcomplexTypegt
lt/xsdelementgt lt/xsdsequencegt
lt/xsdcomplexTypegt lt/xsdelementgt lt/xsdschem
agt
These are referencing element declarations in
other schemas.
Library.xsd
From Costello
19XML Path
- XML
- DTD
- XML Schema
- XML Namespace
- XPath
- DOM Tree
- XSLT
20XPath
- Language for addressing parts of an XML document.
- It operates on the tree data model of XML
- XPath is a syntax for defining parts of an XML
document - XPath uses paths to define XML elements
- It has a non-XML syntax
- XPath defines a library of standard functions
- Such as arithmetic expressions.
- XPath is a major element in XSLT and XML query
languages - XPath is a W3C Standard
21What is XPath
- Like traditional file paths
- XPath uses path expressions to identify nodes in
an XML document. These path expressions look very
much like the expressions you see when you work
with a computer file system - public_html/569/xml.ppt
- Books/book/author/name/FirstName
- Absolute path
- /library/author/book
- Relative path
- author/book
22XML path example
- /library
- /library/author
- //author
- /library/_at_location
- //book_at_titleArtificial Intelligence
- ltlibrary location"Bremen"gt
- ltauthor name"Henry Wise"gt
- ltbook title"Artificial Intelligence"/gt
- ltbook title"Modern Web Services"/gt
- ltbook title"Theory of Computation"/gt
- lt/authorgt
- ltauthor name"William Smart"gt
- ltbook title"Artificial Intelligence"/gt
- lt/authorgt
- ltauthor name"Cynthia Singleton"gt
- ltbook title"The Semantic Web"/gt
- ltbook title"Browser Technology Revised"/gt
- lt/authorgt
- lt/librarygt
23XML Path Example
- Address all author elements
- /library/author
- Addresses all author elements that are children
of the library element node, which resides
immediately below the root - /t1/.../tn, where each ti1 is a child node of
ti, is a path through the tree representation - Address all author elements
- //author
- Here // says that we should consider all elements
in the document and check whether they are of
type author - This path expression addresses all author
elements anywhere in the document
24XPath example
- Select the location attribute nodes within
library element nodes - /library/_at_location
- The symbol _at_ is used to denote attribute nodes
- Select all title attribute nodes within book
elements anywhere in the document, which have the
value Artificial Intelligence - //book/_at_title"Artificial Intelligence
- Select all books with title Artificial
Intelligence - /library/author/book_at_title"Artificial
Intelligence" - Test within square brackets a filter expression
- It restricts the set of addressed nodes.
- Difference with previous query.
- This query addresses book elements, the title of
which satisfies a certain condition. - Previous query collects title attribute nodes of
book elements
25(No Transcript)
26XPath syntax
- A path expression consists of a series of steps,
separated by slashes - A step consists of
- An axis specifier,
- A node test, and
- An optional predicate
- An axis specifier determines the tree
relationship between the nodes to be addressed
and the context node - E.g. parent, ancestor, child (the default),
sibling, attribute node - // is such an axis specifier descendant or self
- childbook select all book elements that are
children of current node - A node test specifies which nodes to address
- The most common node tests are element names
- /library/author
- E.g., addresses all element nodes
- /library/
- comment() selects all comment nodes
- /library/commnets()
27XPath syntax
- Predicates (or filter expressions) are optional
and are used to refine the set of addressed nodes - E.g., the expression 1 selects the first node
- position()last() selects the last node
- position() mod 2 0 selects the even nodes
- XPath has a more complicated full syntax.
- We have only presented the abbreviated syntax
28More examples
- Address the first author element node in the XML
document - //author1
- Address the last book element within the first
author element node in the document - //author1/booklast()
- Address all book element nodes without a title
attribute - //booknot _at_title
29Where we are
- XML
- DTD
- XML Schema
- XML Namespace
- XPath
- DOM Tree
- XSLT
30How to process XML
- XML does not DO anything
- Process XML using general purpose languages
- Java, Perl, C
- DOM is the basis
- Process XML using special purpose languages
- translate the stock XML file to an HTML table.
- Transform the XML XSLT
- tell me the stocks that are higher that 100.
- Query XML XQuery
31DOM (Document Object Model)
- What DOM is application programming interface
(API) for processing XML documents - http//www.w3c.org/DOM/
- Why
- unique interface.
- Platform and language independence.
- How It defines the logical structure of
documents and the way to access and manipulate it - With the Document Object Model, one can
- Create an object tree
- Navigate its structure
- Access, add, modify, or delete elements etc
32XML tree hierarchy
- XML can be described by a tree hierarchy
Document
Unit
Document
Sub-unit
Parent
Unit
Child
Sub-unit
Sibling
33DOM tree model
- Generic tree model
- Node
- Type, name, value
- Attributes
- Parent node
- Previous, next sibling nodes
- First, last child nodes
- Many other entities extends node
- Document
- Element
- Attribute
- ... ...
34DOM class hierarchy
DocumentFragment
Document
Text
CDATASection
CharacterData
Comment
Attr
Node
Element
DocumentType
NodeList
Notation
NamedNodeMap
Entity
DocumentType
EntityReference
ProcessingInstruction
35JavaDoc of DOM API
http//xml.apache.org/xerces-j/apiDocs/index.html
36Remarks on javadoc
- javadoc is a command included in JDK
- It is a useful tool generate HTML description for
your programs, so that you can use a browser to
look at the description of the classes - JavaDoc describes classes, their relationships,
methods, attributes, and comments. - When you write java programs, the JavaDoc is the
first place that you should look at - For core java, there is JavaDoc to describe every
class in the language - To know how to use DOM, look at the javaDoc of
org.w3c.dom package. - If you are a serious java programmer
- you should have the core jdk javaDoc ready on
your hard disk - You should generate the javaDoc for other people
to look at. - To run javadoc, type
- Dgtjavadoc .java
- This is to generate JavaDoc for all the classes
under current directory.
37Methods in Node interface
- Three categories of methods
- Node characteristics
- name, type, value
- Contextual location and access to relatives
- parents, siblings, children, ancestors,
descendants - Node modification
- Edit, delete, re-arrange child nodes
38XML parser and DOM
DOM XML parser
Your XML application
DOM API
DOM Tree
- When you parse an XML document with a DOM parser,
you get back a tree structure that contains all
of the elements of your document - DOM also provides a variety of functions you can
use to examine the contents and structure of the
document.
39DOM tree and DOM classes
ltstocksgt
ltstock Exchangenyse gt
ltstock exchangenasdaqgt
ltnamegt
ltpricegt
ltnamegt
ltpricegt
ltsymbolgt
IBM
105
amzn
15.45
Amazon inc
Element
child
40Use Java to process XML
- Tasks
- How to construct the DOM tree from an XML text
file? - How to get the list of stock elements?
- How to get the attribute value of the second
stock element? - Construct the Document object
- Need to use an XML parser (XML4J)
- Remember to import the necessary packages
- The benefits of DOM the following lines are the
only difference if you use another DOM XML parser.
41Get the first stock element
lt?xml version"1.0" ?gt ltstocksgt ltstock
exchange"nasdaq"gt ltnamegtamazon corplt/namegt
ltsymbolgtamznlt/symbolgt
ltpricegt16lt/pricegt lt/stockgt ltstock
exchange"nyse"gt ltnamegtIBM inclt/namegt
ltpricegt102lt/pricegt lt/stockgt lt/stocksgt
42Navigate to the next sibling of the first stock
element
lt?xml version"1.0" ?gt ltstocksgt ltstock
exchange"nasdaq"gt ltnamegtamazon corplt/namegt
ltsymbolgtamznlt/symbolgt
ltpricegt16lt/pricegt lt/stockgt ltstock
exchange"nyse"gt ltnamegtIBM inclt/namegt
ltpricegt102lt/pricegt lt/stockgt lt/stocksgt
43Be aware the Text object in two elements
lt?xml version"1.0" ?gt ltstocksgt ltstock
exchange"nasdaq"gt ltnamegtamazon corplt/namegt
ltsymbolgtamznlt/symbolgt
ltpricegt16lt/pricegt lt/stockgt ltstock
exchange"nyse"gt ltnamegtIBM inclt/namegt
ltpricegt102lt/pricegt lt/stockgt lt/stocksgt
Question How many children does the stocks node
have?
text
text
text
text
text
text
text
text
text
text
44Remarks on XML parsers
- There are several different ways to categorise
parsers - Validating versus non-validating parsers
- It takes a significant amount of effort for an
XML parser to process a DTD and make sure that
every element in an XML document follows the
rules of the DTD - If only want to find tags and extract information
- use non-validating - Validating or non-validating can be turned on or
off in parsers. - Parsers that support the Document Object Model
(DOM) - Parsers that support the Simple API for XML (SAX)
- Parsers written in a particular language (Java,
C, Perl, etc.).
45Where we are
- XML
- DTD
- XML Schema
- XML Namespace
- XPath
- DOM Tree
- XSLT
46History
XSL
(low-precision graphics, e.g.,HTML, text, XML)
XQuery
(high-precision graphics, e.g., PDF)
XLink/ XPointer
XSL
XSLT
XMLSchemas
XPath
47XSLT(XML Stylesheet Language Transformation)
- XSLT Version 1.0 is a W3C Recommendation, 1999
- http//www.w3.org/Style/XSL/
- XSLT is used to transform XML to other formats
48XSLT basics
- XSLT is an XML document itself
- It is a tree transformation language
- It is a rule-based declarative language
- XSLT program consists of a sequence of rules.
- It is a functional programming language.
49XSLT Example transform to another XML
lt?xml version"1.0" ?gt ltstocksgt ltstock
exchange"nasdaq"gt ltnamegtamazon corp
lt/namegt ltsymbolgtamznlt/symbolgt
ltpricegt16lt/pricegt lt/stockgt ltstock
exchange"nyse"gt ltnamegtIBM inclt/namegt
ltpricegt102lt/pricegt lt/stockgt lt/stocksgt
lt?xml version"1.0gt ltcompaniesgt ltcompanygt
ltvaluegt24 CAD lt/valuegt ltnamegtamazon
corplt/namegt lt/companygt ltcompanygt
ltvaluegt153 CAD lt/valuegt ltnamegtIBM inclt/namegt
lt/companygt lt/companiesgt
?
stock.xml
output
- Rename the element names
- Remove the attribute and the symbol element
- Change the order between name and price.
- Change the US dollar to CAD.
50A most simple XSLT
51Template definition and call
52If statement
53XSLT rule ltxsltemplategt
ltxsltemplate match"stock"gt ltcompanygt ltvaluegt
ltxslvalue-of select"price1.5"/gt
CAD lt/valuegt ltnamegt ltxslvalue-of
select"name"/gt lt/namegt ltcompanygt lt/xsltemplategt
xslt template for ltstockgt
lt?xml version"1.0" ?gt ltstocksgt ltstock
exchange"nasdaq"gt ltnamegtamazon corp
lt/namegt ltsymbolgtamznlt/symbolgt
ltpricegt16lt/pricegt lt/stockgt ltstock
exchange"nyse"gt ltnamegtIBM inclt/namegt
ltpricegt102lt/pricegt lt/stockgt lt/stocksgt
ltcompanygt ltvaluegt get the value of ltpricegt
1.5, i.e. 24 CAD lt/valuegt ltnamegt get the
value of ltnamegt, i.e amazon lt/namegt lt/companygt
Part of the output
stock.xml
54XSLT process model
apply template 1 to ltstocksgt
ltxsltemplate match"/"gt ltcompaniesgt ltxslapply-
templates select"stocks/stock/gt lt/companiesgt lt/x
sltemplategt ltxsltemplate match"stock"gt ltcompa
nygt ltvaluegt ltxslvalue-of select"price1.5"/gt
CADlt/valuegt ltnamegt ltxslvalue-of
select"name"/gt lt/namegtlt/companygt lt/xsltemplategt
ltcompaniesgt apply template 2 to ltstockgt
1 apply template 2 to ltstockgt
2 lt/companiesgt
ltcompanygt ltvaluegt get the value of
ltpricegt1.5,i.e. 24 CAD lt/valuegt ltnamegt get
the value of ltnamegt, i.e amazon lt/namegtlt/companygt
ltcompanygt valuegt get the value of
ltpricegt1.5,i.e., 153 CAD lt/valuegt ltnamegt
get the value of ltnamegt, i.e., IBM lt/namegtlt/compan
ygt
toXML.xsl
xslt output
55Transforming XML to HTML
toHTML.xsl
56Running XSLT from the client side
- Browser gets the XMLXSLT, and interprets them
inside the browser. - How to specify the XSL associated with the XML
file? - lt?xml-stylesheet type"text/xsl"
href"stock.xsl"?gt - Advantages
- Easy to develop and deploy.
- Disadvantages
- Not every browser supports XMLXSL
- Browsers do not support all XSLT features
- Not secure you only want to show part of the XML
data - Not efficient.
57Run XSLT from the server side
- XSL processor transforms the XML and XSLT to
HTML, and the web server send the HTML to the
browser. - Popular tool xalan
- java -classpath xalan/bin/xalan.jar
org.apache.xalan.xslt.Process -in stock.xml -xsl
stock.xsl -out stock.html
XSL Processor
Web server
58Why XML is useful
- Data exchange
- Data integration
59Why XML is useful(cont.)
- Present to different devices
60XML references
- For XML and related specifications www.w3c.org
- For Java support for XML, like XML parser, XSLT
processor www.apache.org - For xml technologies www.xml.com
- XML integrated development environment
www.xmlspy.com