Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide to XML by Cheryl M. Hughes
Copyright © 2003 Pearson Education, Inc. Slide 7-2 CHAPTER 7 New XML Technologies: XSL Style Sheets and XML Schemas
Copyright © 2003 Pearson Education, Inc. Slide 7-3 XSL Style Sheets XSL stands for Extensible Stylesheet Language XSL, like CSS, is a language for defining format and presentation of XML documents The XSL specification was released by the W3C in October of 2001 The XSL specification contains two parts: XSL Formatting Objects (XSL-FO): an XML vocabulary for specifying formatting semantics XSL Transformations (XSLT): a language for transforming XML documents
Copyright © 2003 Pearson Education, Inc. Slide 7-4 XSL Formatting Objects (XSL-FO) XSL-FO is similar to CSS in that it defines formatting and presentation properties The namespace for XSL-FO is: XSL-FO example: 1<fo:block 2font-size=12pt 3font-color=red 4text-align=left> 5Block of text… 6
Copyright © 2003 Pearson Education, Inc. Slide 7-5 XSL Transformations (XSLT) XSLT is used to transform an XML document into another document format (ie – HTML or PDF) The namespace for XSLT is: XSLT is currently the most widely use of XSL
Copyright © 2003 Pearson Education, Inc. Slide 7-6 XSLT Example: XML File Chevy 5 Camaro 6 Blue ,000 9 $18, Ford 13 Mustang 14 Chrome , $30,000
Copyright © 2003 Pearson Education, Inc. Slide 7-7 XSLT Example: XML File (cont.) Jaguar 21 Roadster 22 Red , $23, Porsche Black 32 8, $35,
Copyright © 2003 Pearson Education, Inc. Slide 7-8 XSLT Example: XSL Style Sheet 1 2<xsl:stylesheet version="1.0" xmlns:xsl=" Make and Model 9 Color 10 Year 11 Mileage 12 Price
Copyright © 2003 Pearson Education, Inc. Slide 7-9 XSLT Example: XSL Style Sheet (cont.)
Copyright © 2003 Pearson Education, Inc. Slide 7-10 XML Schemas The XML Schema specification was released by the W3C in May of 2001 XML Schemas, like DTDs, are used to describe the structure of an XML document The XML Schema specification consists of two parts: XML Schema: Structures. This specification consists of a definition language for describing and constraining the content of XML documents XML Schema: Datatypes. This specification defines the datatypes to be used in XML schemas. The namespace for XML Schema is:
Copyright © 2003 Pearson Education, Inc. Slide 7-11 XML Schema Datatypes The XML Schema specification contains a number of built-in datatypes, and also allows developers to create their own datatypes Some of the built-in datatypes: Integer String Date Time
Copyright © 2003 Pearson Education, Inc. Slide 7-12 XML Schema Occurrence Constraints Occurrence constraints define the number of times a particular element can or must occur Attributes: minOccurs : Defines the minimum number of times an element can occur. Default value is 1 maxOccurs : Defines the maximum number of times an element can occur. Default value is 1 Can set the value of the maxOccurs attribute to unbounded to indicate that there is no maximum number of times the element can occur
Copyright © 2003 Pearson Education, Inc. Slide 7-13 XML Schema Simple Type Example XML file: 1 2 < 3 xmlns:xsi = " 4 xsi:noNamespaceSchemaLocation = " _schema.xsd"> 5This is my message 6 Schema file:
Copyright © 2003 Pearson Education, Inc. Slide 7-14 XML Schema Complex Type Example XML file: 1 2 <message 3 xmlns:xsi = " 4 xsi:noNamespaceSchemaLocation = "message_schema.xsd"> 5 Joe Poller 6 Brenda Lane 7 8 Order Joe, 11Please let me know if order number has shipped. 12Thanks, 13Brenda 14 15
Copyright © 2003 Pearson Education, Inc. Slide 7-15 XML Schema Complex Type Example Schema file: <xsd:element name=to type=xsd:string minOccurs-1 maxOccurs=unbounded/>