Tushar Varshney
INTRODUCTION OF XML AND XSLT
XML stands for EXtensible Markup Language.
XML was designed to store and transport data.
XML was designed to be both human- and machine-readable.
•XSLT stands for Extensible Stylesheet Language Transformations
•XSLT is used to transform XML documents into other kinds of documents--
usually, but not necessarily, XHTML
•XSLT uses two input files:
• The XML document containing the actual data
• The XSL document containing both the “framework” in
which to insert the data, and XSLT commands to do so
example
File data.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="render.xsl"?>
<message>Howdy!</message>
File render.xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0”
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- one rule, to transform the input root (/) -->
<xsl:template match="/">
<html><body>
<h1><xsl:value-of select="message"/></h1>
</body></html>
</xsl:template>
</xsl:stylesheet>
6
Where XSLT can be used
With an appropriate program, such as Xerces, XSLT can be used to
read and write files
A server can use XSLT to change XML files into HTML files before
sending them to the client
A modern browser can use XSLT to change XML into HTML on the
client side
This is what we will mostly be doing in this class
Most users seldom update their browsers
If you want “everyone” to see your pages, do any XSL
processing on the server side
Otherwise, think about what best fits your situation
7
An XML Schema describes the structure of an XML document, just like a DTD.
An XML document with correct syntax is called "Well Formed".
An XML document validated against an XML Schema is both "Well Formed"
and "Valid".
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name=“qualification“ type=“xs:string”/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
… …
</xs:sequence>
<xs:attribute name="isbn" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="title" type="nameType"/>
… …
</xs:sequence>
<xs:attribute name="isbn" type="isbnType" use="required"/>
</xs:complexType>
Declaration
Type Definition <xs:element name="book" type="bookType"/>
<book isbn="0836217462">
<title>
Being a Dog Is a Full-Time Job
</title>
……
</book>
General Problem
Several-hundred-page spec in a very technical language
Practical Limitations of expressibility
content and attribute declarations cannot depend on
attributes or element context.
Technical Problem
The notion of “type” adds an extra layer of confusing
complexity
…

Introduction of xml and xslt

  • 1.
  • 2.
    XML stands forEXtensible Markup Language. XML was designed to store and transport data. XML was designed to be both human- and machine-readable.
  • 5.
    •XSLT stands forExtensible Stylesheet Language Transformations •XSLT is used to transform XML documents into other kinds of documents-- usually, but not necessarily, XHTML •XSLT uses two input files: • The XML document containing the actual data • The XSL document containing both the “framework” in which to insert the data, and XSLT commands to do so
  • 6.
    example File data.xml: <?xml version="1.0"?> <?xml-stylesheettype="text/xsl" href="render.xsl"?> <message>Howdy!</message> File render.xsl: <?xml version="1.0"?> <xsl:stylesheet version="1.0” xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- one rule, to transform the input root (/) --> <xsl:template match="/"> <html><body> <h1><xsl:value-of select="message"/></h1> </body></html> </xsl:template> </xsl:stylesheet> 6
  • 7.
    Where XSLT canbe used With an appropriate program, such as Xerces, XSLT can be used to read and write files A server can use XSLT to change XML files into HTML files before sending them to the client A modern browser can use XSLT to change XML into HTML on the client side This is what we will mostly be doing in this class Most users seldom update their browsers If you want “everyone” to see your pages, do any XSL processing on the server side Otherwise, think about what best fits your situation 7
  • 8.
    An XML Schemadescribes the structure of an XML document, just like a DTD. An XML document with correct syntax is called "Well Formed". An XML document validated against an XML Schema is both "Well Formed" and "Valid".
  • 9.
    <?xml version="1.0" encoding="utf-8"?> <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="book"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="author" type="xs:string"/> <xs:element name=“qualification“ type=“xs:string”/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
  • 10.
    <xs:element name="book"> <xs:complexType> <xs:sequence> <xs:element name="title"type="xs:string"/> … … </xs:sequence> <xs:attribute name="isbn" type="xs:string"/> </xs:complexType> </xs:element> <xs:complexType name="bookType"> <xs:sequence> <xs:element name="title" type="nameType"/> … … </xs:sequence> <xs:attribute name="isbn" type="isbnType" use="required"/> </xs:complexType> Declaration Type Definition <xs:element name="book" type="bookType"/> <book isbn="0836217462"> <title> Being a Dog Is a Full-Time Job </title> …… </book>
  • 11.
    General Problem Several-hundred-page specin a very technical language Practical Limitations of expressibility content and attribute declarations cannot depend on attributes or element context. Technical Problem The notion of “type” adds an extra layer of confusing complexity …

Editor's Notes

  • #11 Here are examples for declaration and definition. In the first block, we declare an element named “book”, while in an instance XML document, we can fill out values. In the second block, we define a complex data type named “bookType”, and then we can declare an element,book, somewhere, based on the type.