CSE 510 Web Data Engineering XML, XHTML, XSLT and Web Application - - PowerPoint PPT Presentation

cse 510 web data engineering
SMART_READER_LITE
LIVE PREVIEW

CSE 510 Web Data Engineering XML, XHTML, XSLT and Web Application - - PowerPoint PPT Presentation

CSE 510 Web Data Engineering XML, XHTML, XSLT and Web Application Programming Evolving as We Speak UB CSE 510 Web Data Engineering XML-based Model 2 (MVC) Architecture of Today View: XSLT-based presentation XML/XML Schema-defined


slide-1
SLIDE 1

CSE 510 Web Data Engineering

XML, XHTML, XSLT and Web Application Programming Evolving as We Speak…

UB CSE 510 Web Data Engineering

slide-2
SLIDE 2

UB CSE 510 Web Data Engineering 2

XML-based Model 2 (MVC) Architecture of Today

Model - Controller View: XSLT-based presentation XML/XML Schema-defined interaction

slide-3
SLIDE 3

UB CSE 510 Web Data Engineering 3

XML-based Model 2 (MVC) Architecture of Tomorrow

Controller View: XSLT-based presentation XML/XML Schema-defined interaction Model uses Web services and XML-wrapped sources XQuery or WSDL requests / XML results

slide-4
SLIDE 4

UB CSE 510 Web Data Engineering 4

XHTML: HTML Without Syntactic Sugar

  • Tim Berners-Lee, Robert Cailliau, Jean-François Groff:

The World-Wide Web. Computer Networks 25(4-5): 454-459 (1992) <dt name="www"> <img src="greenball.gif"/> Tim Berners-Lee, Robert Cailliau, Jean-François Groff: <a href="http://scholar.google.com/scholar?q=%22The +World%2DWide+Web%22"> The World-Wide Web. </a> <i>Computer Networks 25(4-5): 454-459 (1992)</i> </dt>

slide-5
SLIDE 5

UB CSE 510 Web Data Engineering 5

XML

Executive Summary:

  • XML = XHTML + user-definable ("semantic") tags
  • Separation of data and its presentation

=> Simple, very flexible data exchange format:

  • semistructured data model

=> New applications:

  • Information exchange (B2B), sharing (diglib),

integration ("mediation"), archival, …

  • Web application development:
  • Cleaner separation of View from Controller
  • Unifying data model for multiple information sources
slide-6
SLIDE 6

UB CSE 510 Web Data Engineering 6

What’s Wrong with HTML …

<dt name="www"> <img src="greenball.gif"/> Tim Berners-Lee, Robert Cailliau, Jean-François Groff: <a href="http://scholar.google.com/scholar?q=%22The +World%2DWide+Web%22"> The World-Wide Web. </a> <i>Computer Networks 25(4-5): 454-459 (1992)</i> </dt>

No Explicit Structure, Semantics, or Object-Orientation

Author Conference Title

slide-7
SLIDE 7

UB CSE 510 Web Data Engineering 7

… and Some Repercussions

=> HTML is inappropriate for

– Data exchange – Separation of logical from presentation aspects of a Web application’s view

slide-8
SLIDE 8

UB CSE 510 Web Data Engineering 8

XML is Based on Markup

<bibliography> <paper id="www"> <authors> <author>Tim Berners-Lee</author> <author>Robert Cailliau</author> <author>Jean-François Groff</author> </authors> <fullPaper source="http://scholar.google.com/scholar?q= %22The+World%2DWide+Web%22"/> <title>The World-Wide Web.</title> <booktitle> Computer Networks 25(4-5): 454-459 (1992) </booktitle> </paper> </bibliography>

Markup indicates structure and semantics Decoupled from presentation

slide-9
SLIDE 9

UB CSE 510 Web Data Engineering 9

<bibliography> <paper id="www"> <authors> <author>Tim Berners-Lee</author> <author>Robert Cailliau</author> <author>Jean-François Groff</author> </authors> <fullPaper source="http://scholar.google.com/scholar?q= %22The+World%2DWide+Web%22"/> <title>The World-Wide Web.</title> <booktitle> Computer Networks 25(4-5): 454-459 (1992) </booktitle> </paper> </bibliography>

Elements and their Content

Element Element Name Character Content Element Content Empty Element

slide-10
SLIDE 10

UB CSE 510 Web Data Engineering 10

Element Attributes

<bibliography> <paper id="www"> <authors> <author>Tim Berners-Lee</author> <author>Robert Cailliau</author> <author>Jean-François Groff</author> </authors> <fullPaper source="http://scholar.google.com/scholar?q= %22The+World%2DWide+Web%22"/> <title>The World-Wide Web.</title> <booktitle> Computer Networks 25(4-5): 454-459 (1992) </booktitle> </paper> </bibliography>

Attribute Name Attribute Value

slide-11
SLIDE 11

UB CSE 510 Web Data Engineering 11

XML, XHTML = Labeled Ordered Trees

<bibliography> <paper id="www"> <authors> <author>Tim</author> <author>Robert</author> ... </authors> <title> The World-Wide Web. </title> ... </paper> </bibliography>

bibliography paper authors author author ... title fullpaper Tim Robert The World-Wide Web. ... paper

≈ semistructured data ≈ labeled trees/graphs can also represent

  • relational and
  • object-oriented data

@id www

slide-12
SLIDE 12

UB CSE 510 Web Data Engineering 12

Attributes

<person id="tim"> Tim’s info </person> <bibliography> <paper id="www" role="publication"> <authors> <author authorRef="tim"> Tim Berners-Lee</author> </authors> <fullPaper source="wwwPaper"/> <title>The World-Wide Web.</title> <related papers="browsers html"/> </paper> </bibliography>

CDATA (character data) Object Identity Attribute IDREF intra-document reference Reference to external ENTITY

slide-13
SLIDE 13

UB CSE 510 Web Data Engineering 13

Turning XML into HTML: XSLT

  • Why Stylesheets?

– Separation of content (XML) from presentation (XSL)

  • Why not just CSS for XML?

– XSL is far more powerful: – selecting elements – transforming the XML tree – content based display (result may depend on data)

slide-14
SLIDE 14

UB CSE 510 Web Data Engineering 14

Using XSLT for View Components

XML, XSLT Server Side Client Side HTML Browser shows HTML XML, XSLT Server Side Client Side Browser runs XSLT on XML to Produce HTML View Component runs XSLT on XML Action component/ Controller Action component/ Controller

slide-15
SLIDE 15

UB CSE 510 Web Data Engineering 15

XSLT Overview

  • XSLT stylesheets are denoted in XML syntax
  • XSL components:
  • 1. A language for transforming XML documents

(XSLT: integral part of the XSL specification)

  • 2. An XML formatting vocabulary

(Formatting Objects: >90% of the formatting properties inherited from CSS)

slide-16
SLIDE 16

UB CSE 510 Web Data Engineering 16

XSLT Processing Model

XML source tree XML,HTML,… result tree XSL stylesheet Transformation

slide-17
SLIDE 17

UB CSE 510 Web Data Engineering 17

XSLT Processing Model

  • XSL stylesheet: collection of template rules
  • template rule: (pattern ⇒ template)
  • main steps:

– match pattern against source tree – instantiate template (replace current node “.” by the template in the result tree) – select further nodes for processing

  • control can be

– program-driven ("pull": <xsl:foreach> ...) – data/event-driven ("push": <xsl:apply-templates> ...)

slide-18
SLIDE 18

UB CSE 510 Web Data Engineering 18

Template Rule: Example

<xsl:template match="product"> <table> <xsl:apply-templates select="sales/domestic"/> </table> <table> <xsl:apply-templates select="sales/foreign"/> </table> </xsl:template>

  • 1. match pattern: process <product> elements
  • 2. instantiate template: replace each product with two

HTML tables

  • 3. select the <product> grandchildren (“sales/domestic”,

“sales/foreign”) for further processing Pattern Template

slide-19
SLIDE 19

UB CSE 510 Web Data Engineering 19

Example of Turning XML into HTML

<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="FitnessCenter.xsl"?> <FitnessCenter> <Member level="platinum"> <Name>Jeff</Name> <Phone type="home">555-1234</Phone> <Phone type="work">555-4321</Phone> <FavoriteColor>lightgrey</FavoriteColor> </Member> </FitnessCenter>

slide-20
SLIDE 20

UB CSE 510 Web Data Engineering 20

HTML Document in an XSL Template

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head><title>Welcome</title></head> <body> Welcome! </body> </html> </xsl:template> </xsl:stylesheet>

slide-21
SLIDE 21

UB CSE 510 Web Data Engineering 21

Extracting the Member Name

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head><title>Welcome</title></head> <body> Welcome <xsl:value-of select="/FitnessCenter/Member/Name"/>! </body> </html> </xsl:template> </xsl:stylesheet>

slide-22
SLIDE 22

UB CSE 510 Web Data Engineering 22

Navigating the XML Document

  • Extracting values from an XML Document:

– use the <xsl:value-of select="…"/> XSL element

  • Navigating:

– The slash ("/") indicates parent/child relationship – A slash at the beginning of the path indicates that it is an absolute path, starting from the top of the XML document /FitnessCenter/Member/Name

Start from the top of the XML document, go to the FitnessCenter element, from there go to the Member element, and from there go to the Name element

slide-23
SLIDE 23

UB CSE 510 Web Data Engineering 23

Element ¡ FitnessCenter ¡ Document ¡ / ¡ PI ¡ <?xml ¡version=“1.0”?> ¡ Element ¡ Member ¡ Element ¡ Name ¡ Element ¡ Phone ¡ Element ¡ Phone ¡ Element ¡ FavoriteColor ¡ Text ¡ Jeff ¡ Text ¡ 555-­‑1234 ¡ Text ¡ 555-­‑4321 ¡ Text ¡ lightgrey ¡

XML DOM Tree

slide-24
SLIDE 24

UB CSE 510 Web Data Engineering 24

Extract FavoriteColor and Use It As bgcolor

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head><title>Welcome</title></head> <body bgcolor="{/FitnessCenter/Member/FavoriteColor}"> Welcome <xsl:value-of select="/FitnessCenter/Member/Name"/>! </body> </html> </xsl:template> </xsl:stylesheet>

slide-25
SLIDE 25

UB CSE 510 Web Data Engineering 25

Note

  • Attribute values cannot contain "<" nor ">"

– Consequently, the following is NOT valid:

<body bgcolor=" <xsl:value-of select='/FitnessCenter/Member/FavoriteColor’ /> ">

  • To extract the value of an XML element and use

it as an attribute

  • value you must use curly braces:

<body bgcolor="{/FitnessCenter/Member/FavoriteColor}">

Evaluate the expression within the curly braces, and assign the value to the attribute

slide-26
SLIDE 26

UB CSE 510 Web Data Engineering 26

Extract the Home Phone Number

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html> <head><title>Welcome</title></head> <body bgcolor="{/FitnessCenter/Member/FavoriteColor}"> Welcome <xsl:value-of select="/FitnessCenter/Member/Name"/>! <br /> Your home phone number is: <xsl:value-of select="/FitnessCenter/Member/Phone[@type='home']"/> ...

slide-27
SLIDE 27

UB CSE 510 Web Data Engineering 27

Creating the Result Tree

  • Further XSL elements for

– Numbering – <xsl:number value="position()" format="1"> – Conditions – <xsl:if test="position() mod 2 = 0"> – Repetition…

slide-28
SLIDE 28

UB CSE 510 Web Data Engineering 28

More on XSL

  • XSL(T):

– Conflict resolution for multiple applicable rules – Modularization <xsl:include> <xsl:import> – …

  • XSL Formatting Objects

– a la CSS

  • XPath (navigation syntax + functions)

= XSLT ∩ XPointer