XML and XSL - PowerPoint PPT Presentation

About This Presentation
Title:

XML and XSL

Description:

Serve sites and formats based on user need. Text-based (text readers, slow links, low-tech) ... 'Metalanguage' For describing information. XML Design Goals ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 40
Provided by: ukol
Category:
Tags: xml | xsl | metalanguage

less

Transcript and Presenter's Notes

Title: XML and XSL


1
XML and XSL
Institutional Web Management 2001 Organising
Chaos
2
Running order
  • Background
  • All about XML
  • All about XSL
  • Hands-on XML and XSL
  • Publishing engines
  • Example applications
  • Crystal balls

3
Background
  • Mark Ray and Andrew Savory
  • Using XML since 1996
  • Used a variety of tools and methods

4
XML and XSL
  • W3C specifications
  • Separation of Concerns
  • Reuse of data
  • Multiple output formats
  • Styles tailored to reader / Standardised styles

5
Applications of XML and XSL
  • Static information
  • Institutional web sites
  • Prospectuses
  • Course catalogues
  • Dynamic information
  • News or event information services
  • Course catalogues
  • Staff directories

6
Benefits of XML and XSL
  • Standards-based, format-independent
  • Serve sites and formats based on user need
  • Text-based (text readers, slow links, low-tech)
  • Netscape / Internet Explorer specifc
  • TV, Phone, PDA
  • PDF, SVG, VRML, ...
  • Simplification of web site management...

7
The management bit
  • Management
  • Decide what the site should contain, how it
    should behave and how it should appear
  • Content
  • Responsible for writing, owning, managing the
    site content

8
The management bit
  • Logic
  • Responsible for integration with dynamic content
    generation
  • Style
  • Responsible for information presentation, look
    feel, site graphics and maintenance

9
What is XML?
  • eXtensible Markup Language
  • Not a fixed format
  • 'Metalanguage'
  • For describing information

10
XML Design Goals
  1. XML shall be straightforwardly usable over the
    Internet.
  2. XML shall support a wide variety of applications.
  3. XML shall be compatible with SGML.
  4. It shall be easy to write programs which process
    XML documents.
  5. The number of optional features in XML is to be
    kept to the absolute minimum, ideally zero.

11
XML Design Goals
  1. XML documents should be human-legible and
    reasonably clear.
  2. The XML design should be prepared quickly.
  3. The design of XML shall be formal and concise.
  4. XML documents shall be easy to create.
  5. Terseness is of minimal importance.

12
Structure of an XML document
  • lt?xml version"1.0"?gt
  • ltPARENTgt
  • ltCHILDgt
  • This is content.
  • lt/CHILDgt
  • ltEMPTY/gt
  • lt/PARENTgt

13
A first XML document
  • Construct a well-formed XML document using the
    following tags
  • xml opening tag
  • page
  • title
  • content
  • para
  • Don't forget to add the closing tags!

14
Differences to HTML
  • Order
  • lttag1gtlttag2gtlt/tag1gtlt/tag2gt WRONG
  • lttag1gtlttag2gtlt/tag2gtlt/tag1gt RIGHT
  • Balance
  • lttag1gtlttag2gtlt/tag2gt WRONG
  • lttag1gtlttag2gtlt/tag2gtlt/tag1gt RIGHT
  • Case
  • lttag1gtlttag2gtlt/TAG2gtlt/TAG1gt WRONG
  • lttag1gtlttag2gtlt/tag2gtlt/tag1gt RIGHT

15
Differences to HTML
  • Attributes
  • lttag1 classwronggt WRONG
  • lttag1 class"right"gt RIGHT
  • Empty Tags
  • lttag1 class"wrong"gt WRONG
  • lttag1 class"wrong" /gt RIGHT
  • XML is stricter
  • ...and therefore better!

16
Well-formed vs. Valid
  • Exactly what they say
  • Well-formed means it's written correctly
  • Valid means we can validate it

17
A well-formed example
  • lt?xml version"1.0"?gt
  • ltPARENTgt
  • ltCHILDgt
  • ltMARK NUMBER"1" LISTED"yes" TYPE"natural"/gt
  • ltNAMEgt
  • ltLASTNAMEgtchildlt/LASTNAMEgt
  • ltFIRSTNAMEgtsecondlt/FIRSTNAMEgt
  • lt/NAMEgt
  • lt/CHILDgt
  • lt/PARENTgt

18
A valid example
  • lt?xml version"1.0"?gt
  • lt!DOCTYPE PARENT
  • lt!ELEMENT PARENT (CHILD)gt
  • lt!ELEMENT CHILD (MARK?,NAME)gt
  • lt!ELEMENT MARK EMPTYgt
  • lt!ELEMENT NAME (LASTNAME,FIRSTNAME)gt
  • lt!ELEMENT LASTNAME (PCDATA)gt
  • lt!ELEMENT FIRSTNAME (PCDATA)gt
  • lt!ATTLIST MARK
  • NUMBER ID REQUIRED
  • LISTED CDATA FIXED "yes"
  • TYPE (naturaladopted) "natural"gt
  • lt!ENTITY STATEMENT "This is well-formed XML"gt
  • gt
  • ltPARENTgt
  • STATEMENT
  • ltCHILDgt
  • ltMARK NUMBER"1" LISTED"yes" TYPE"natural"/gt
  • ltNAMEgt

19
Document Type Definitions
  • First standard mechanism for XML validation
  • Define the role and structure of XML elements
  • Sufficient for simple XML schemas
  • Don't support namespaces
  • Use non-XML syntax

20
XSchema
  • XML structural definition language of choice
  • Defines a class of XML document
  • Supports name spaces
  • More powerful

21
Xschema example
  • lt?xml version"1.0"?gt
  • ltxsdschema xmlnsxsd"http//www.w3.org/2001/XMLS
    chema"gt
  • ltxsdannotationgt
  • ltxsddocumentation xmllang"en"gt
  • Example Schema for IWM workshop
  • lt/xsddocumentationgt
  • lt/xsdannotationgt
  • ltxsdelement name"page" type"page"/gt
  • ltxsdcomplexType name"page"gt
  • ltxsdsequencegt
  • ltxsdelement name"title" type"xsdstring"/gt
  • ltxsdelement name"content"
    type"pageContent"/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • ltxsdcomplexType name"pageContent"gt
  • ltxsdsequencegt

22
What is XSL?
  • Preferred style sheet language of XML
  • a method for transforming XML documents
  • a method for defining XML parts and patterns
  • a method for formatting XML documents
  • An application of XML (same formatting rules)

23
Hands-on XML
  • Create the following XML document
  • lt?xml version"1.0"?gt
  • ltpagegt
  • lttitlegtHellolt/titlegt
  • ltcontentgt
  • ltparagtThis is my first XML page!lt/paragt
  • lt/contentgt
  • lt/pagegt
  • Save it as hello_world.xml

24
Uploading the file
  • Navigate to the site provided
  • Click on "upload.html"
  • Beside the "file to upload" box, click on
    "choose"
  • Select the file you want to upload
  • Click on "upload"

25
Viewing the file
  • If you see the file you wanted to upload and
    receive a "File written successfully" message...
  • Click on "Content", then the name of the file

26
Structure of an XSL stylesheet
  • Most templates have the following form
  • ltxsltemplate match"emphasis"gt
  • ltigtltxslapply-templates/gtlt/igt
  • lt/xsltemplategt
  • The whole ltxsltemplategt element is a template
  • The match pattern determines where this template
    applies

27
Structure of an XSL stylesheet
  • Literal result element(s) come from non-XSL
    namespace(s)
  • XSLT elements come from the XSL namespace

28
Hands-on XSL
  • Create the following XSL stylesheet
  • lt?xml version"1.0"?gt
  • ltxslstylesheet version"1.0" xmlnsxsl"http//ww
    w.w3.org/1999/XSL/Transform"gt
  • ltxsltemplate match"page"gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtltxslvalue-of select"title"/gtlt/titlegt
  • lt/headgt
  • ltbody bgcolor"white" alink"red" link"blue"
    vlink"blue"gt
  • ltxslapply-templates/gt
  • lt/bodygt
  • lt/htmlgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

29
Uploading the file
  • Navigate to the site provided
  • Click on "upload.html"
  • Beside the "file to upload" box, click on
    "choose"
  • Select the file you want to upload
  • Click on "upload"

30
Publishing engines
  • Cocoon
  • Java-based
  • AxKit
  • Perl-based
  • 4Suite
  • Python
  • Others or roll your own

31
Viewing the file
  • If you see the file you wanted to upload and
    receive a "File written successfully" message...
  • Click on "View site in cocoon"
  • Select the file you uploaded and the stylesheet
    you want to view it in

32
Hands-on XSL
  • Add the following to the XSL stylesheet
  • ltxsltemplate match"title"gt
  • lth2 style"color navy text-align center"gt
  • ltxslapply-templates/gt
  • lt/h2gt
  • lt/xsltemplategt
  • ltxsltemplate match"para"gt
  • ltp align"left"gt
  • ltigtltxslapply-templates/gtlt/igt
  • lt/pgt
  • lt/xsltemplategt

33
New platforms, new beginnings?
  • The old way of publishing
  • Repurposing
  • The new way of publishing
  • Target multiple platforms
  • Multiple stylesheets
  • Multiple formats

34
Browser-specific content
  • ltmapselectgt
  • ltmapwhen test"lynx"gt
  • ltmaptransform src"stylesheets/simple-page2html-l
    ynx.xsl"/gt
  • lt/mapwhengt
  • ltmapotherwisegt
  • ltmaptransform src"stylesheets/simple-page2html.x
    sl"/gt
  • lt/mapotherwisegt
  • lt/mapselectgt

35
Lynx-friendly XSL stylesheet
  • Add the following to your XSL stylesheet
  • lth2gtThis site is lynx-friendlylt/h2gt
  • Save the stylesheet as
  • simple-page2html-lynx.xsl

36
Uploading the file
  • Navigate to the site provided
  • Click on "upload.html"
  • Beside the "file to upload" box, click on
    "choose"
  • Select the file you want to upload
  • Click on "upload"

37
Viewing the file
  • If you see the file you wanted to upload and
    receive a "File written successfully" message...
  • Click on "View site in cocoon"
  • Select the file you uploaded and the stylesheet
    you want to view it in

38
Where next?
  • The semantic web

39
References
  • http//www.ibm.com/developerworks/papers.nsf/dw/xm
    l-papers-bytopic?OpenDocumentCount500
  • http//www.xml101.com/
  • http//nwalsh.com/docs/tutorials/xsl/
Write a Comment
User Comments (0)
About PowerShow.com