33
MSc IT Multimedia XML & XSLT P. Muneesawang

MSc IT Multimedia XML & XSLT P. Muneesawang. 2 Outline Why XML XSL

Embed Size (px)

Citation preview

MSc ITMultimedia

XML & XSLT

P. Muneesawang

2

Outline• Why

• XML

• XSL

3

World Wide Web Consortium• W3C, founded in October 1994: http://www.w3.org/

• Purpose: develop common protocols that promote WWW’s evolution and ensure its interoperability

• User Interface Domain

Hypertext Markup Language (HTML), Cascading Style Sheets (CSS), Document Object Model (DOM), Scalable Vector Graphics (SVG), SMIL

• Technology and Society Domain

Platform for Privacy Preferences (P3P), Platform for Internet Content Selection (PICS), Resource Description Framework (RDF)

• Architecture DomainHypertext Transfer Protocol (HTTP), Extensible Markup

Language (XML)

...Follow links at http://www.w3.org/ for more details…

4

Why• Many XML Issues Related to Multimedia:

• XML Data Representation

• XML Schemes and MPEG

• XML and Multimedia Data Indexing

• XML and Multimedia Data Caching

• Multimedia applications and XML

• XML DTDs and Database Schemas

• Security

• But....

• We need to start with the basics….

5

Why• Full Text Encoding or Mark-up allows:

• the representation of structure (original or otherwise -Headers, sections, cuts, divisions etc)

• to make explicit an interpretation or

• document searching (e.g. find by artist x, and/or by reference y)

• output in a specific format

• re-use in different formats (one document, many outputs e.g. PC, PDA, Phone, Print)

• platform & software-independence

• wide distribution

• preserve content

6

Why• Particularly useful for:

• collating/providing different versions

• designing interactive multimedia editions

• recording metadata (date of creation, copyright status, change history, etc)

7

Mark-up Languages• A set of rules that typically state:

• what kind of mark-up is allowed

• where it is allowed required

• how its elements relate to each other

• how to tell mark-up from content

eXtensible Makeup Language (XML)

9

XML• XML is a method for putting structured data in a

text file

• XML looks a bit like HTML but isn't HTML

• XML is text, can be read by humans and computers

• XML is a family of technologies

• XML is verbose, but that is less of a problem

• XML is new, but not that new

• XML is license-free, platform-independent and well-supported

10

What is XML?• Interchange structured documents over the

internet

• Start and end of each logical part (elements)

• DTD formal model allows users to check validity

• Does not require presence of DTD

• A family of languages e.g. XSLT, XSL, XPath

11

What is XML?• XML allows users to:

• bring multiple files together to form compound documents

• identify where images, sounds, video should be incorporated

• provide processing control information

• add editorial comments to a file

12

What is XML?• XML is not

• a predefined set of tags

• a standardized template for producing particular document types

13

HTML Example<! -- Price list for individual fruits --><ul><! -- Fruit --><li>Apples</li><! -- Price --><li>£1</li><! -- Fruit --><li>Oranges</li><! -- Price --><li>£2</li></ul>

14

XML Example

<FruitPriceList><Fruit>Apples</Fruit>

<Price>£1</Price><Fruit>Oranges</Fruit>

<Price>£2</Price></FruitPriceList>

15

XML TreeWell-formed XML treeWell-formed XML tree

16

XML tree

Not well-formed XML treeNot well-formed XML tree

17

XML Components

• Documents composed of entities

• Entities can contain one or more logical elements

• Each element can have certain attributes

18

XML use• Elements and attributes entered between matched pairs of angle brackets <….>

• Entity references start with an ampersand and end with a semi-colon &….;

19

XML Use<?xml version=“1.0” encoding=“US2” standalone=“yes”><! DOCTYPE memo SYSTEM “http://www.acme.com/memo.dtd><memo><to>All Staff</to><from>Ian Anderson</from><date>20 January</date><subject>Lottery</subject><text>The HATII syndicate has won the lottery and we can all quit tomorrow.</text></memo>

20

Defining your Tag Set

Must create a DTD

<! DOCTYPE memo [<! ELEMENT memo (to, from, date, subject?, para+) ><! ELEMENT para (#PCDATA) ><! ELEMENT to (#PCDATA) ><! ELEMENT from (#PCDATA) ><! ELEMENT data (#PCDATA) ><! ELEMENT subject (#PCDATA) >] >

21

Using XML Coded Text

• XML Processing Instruction<?xml version=“1.0” encoding=“US2”

standalone=“yes”>• Document Type Declaration (internal orexternal subset)

<! DOCTYPE memo SYSTEM“http://www.myco.com/memo.dtd >

• Document InstanceElement type name must match document type name

22

Using XML Coded Text

If all three components present, and document instance conforms to rules defined in document type definition, the document is valid.

If only document instance is present all XML processor can do is check document is well-formed

23

Where now?• XML Multimedia Developments

• PMML - Pervasive Multimedia Markup Language

• RDF - Resource Description Framework (Multimedia specific): an infrastructure that enables the encoding, exchange, and reuse of structured metadata.

• SMIL - Synchronized Multimedia Integration Language

24

Context: Informedia Digital Video Library

25

Sample XML for Informedia Results Set

<?xml version="1.0" ?><?xml version="1.0" ?><IDVLResults<IDVLResults xmlns:im="x-schema:idvResSchema.xml" xmlns:im="x-schema:idvResSchema.xml">><im:doc><im:doc> <im:id><im:id>5519555195</im:id><im:pos></im:id><im:pos>00</im:pos><im:shot></im:pos><im:shot>16674991667499</im:shot></im:shot> <im:d_yr><im:d_yr>19991999</im:d_yr><im:d_mo></im:d_yr><im:d_mo>1212</im:d_mo><im:d_day></im:d_mo><im:d_day>22</im:d_day></im:d_day> <im:score><im:score>100100</im:score><im:dur></im:score><im:dur>2993029930</im:dur><im:mmss></im:dur><im:mmss>0:290:29</im:mmss></im:mmss> <im:title><im:title>The Maker of Cherry Garcia and Rainforest Crunch Ice Cream Could The Maker of Cherry Garcia and Rainforest Crunch Ice Cream Could

Soon be Scooped Up; Ice Cream Maker Didn't Name PotentialSoon be Scooped Up; Ice Cream Maker Didn't Name Potential</im:title></im:title></im:doc><im:doc></im:doc><im:doc> <im:id><im:id>5477054770</im:id><im:pos></im:id><im:pos>11</im:pos><im:shot></im:pos><im:shot>21115782111578</im:shot></im:shot> <im:d_yr><im:d_yr>19991999</im:d_yr><im:d_mo></im:d_yr><im:d_mo>1111</im:d_mo><im:d_day></im:d_mo><im:d_day>1919</im:d_day></im:d_day> <im:score><im:score>7070</im:score><im:dur></im:score><im:dur>196480196480</im:dur><im:mmss></im:dur><im:mmss>3:163:16</im:mmss></im:mmss> <im:title><im:title>So, While Ice Cream Parlor Closed, in Suite Next Door to where Tim and So, While Ice Cream Parlor Closed, in Suite Next Door to where Tim and

Heidi Manipulate Bones, Tim and Heidi now also Fill Jars Heidi Manipulate Bones, Tim and Heidi now also Fill Jars </im:title></im:title></im:doc></IDVLResults></im:doc></IDVLResults>

26

Other W3C Recommendations• XSLT – Extensible Stylesheet Language

Transformations

• XPath – XML Path Language

• XML Schema

27

Adding Style to XML• XML only text-based, not for visually

presentation.

• Extensible Stylesheet Language (XSL) and XSL Transformations (XSLT) available (XSL as working draft, XSLT as W3C Recommendation Nov. 16, 1999, http://www.w3.org/TR/xslt)• XSLT: a language for transforming XML

documents into other XML documents

• XPATH: a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer

28

XML example<?xml version="1.0" encoding="windows-874"?>

<?xml-stylesheet type="text/xsl" href="XSL_For_02-01.xsl"?>

<myfriend>

<people>

<id>001</id>

<name>น.ส. ชลธิ�ชา ศรีดา</name>

<address>กรี งเทพ</address>

<telephone>02914-6758</telephone>

<email>[email protected]</email>

<url>http://www.chon.com/</url>

</people>

<people>

<id>002</id>

<name> นายศ ภช�ย สมพาน�ช</name>

<address>กรี งเทพ</address>

<telephone>02524-1234</telephone>

<email>[email protected]</email>

<url>http://www.vbth.cjb.net/</url>

</people>

</myfriend>

29

XSL example<?xml version="1.0" encoding="windows-874"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"><xsl:template match="/"><!-- สร้�างส�วนหัวเอกสาร้ HTML ตามปกต� --> <html><head><title> เบื้��องต�นการ้ใช้�งานภาษา XSL ร้�วมกบื้ภาษา XML </title></head> <body>

<!-- สร้�างส�วนหัวของแต�ละคอลมน� --><table width="100%" border="1" style="border-collapse: collapse"> <tr> <td width="5%" bgcolor="black"><font face="MS Sans Serif" size="2" color="white"><b>ร้หัส</b></font></td> <td width="20%" bgcolor="black"><font face="MS Sans Serif" size="2" color="white"><b>ช้��อ</b></font></td> <td width="15%" bgcolor="black"><font face="MS Sans Serif" size="2" color="white"><b>ที่!�อยู่#�</b></font></td> <td width="10%" bgcolor="black"><font face="MS Sans Serif" size="2" color="white"><b>โที่ร้ศัพที่�</b></font></td> <td width="20%" bgcolor="black"><font face="MS Sans Serif" size="2" color="white"><b>E-mail</b></font></td> <td width="30%" bgcolor="black"><font face="MS Sans Serif" size="2" color="white"><b>โอมเพจ</b></font></td> </tr>

<!-- เร้��มต�นอ�านข�อม#ลจากแหัล�งข�อม#ล 02-01_With_XSL.xml โดยู่การ้วนล#ป --><xsl:for-each select="myfriend/people"> <tr> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="id"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="name"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="address"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="telephone"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="email"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="url"/></font></td> </tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>

30

XSLT, larger font, 1 of 2<?xml version="1.0" encoding="windows-874"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"><xsl:template match="/"><!-- สร้�างส�วนหัวเอกสาร้ HTML ตามปกต� --> <html><head><title> เบื้��องต�นการ้ใช้�งานภาษา XSL ร้�วมกบื้ภาษา XML </title></head> <body>

<!-- สร้�างส�วนหัวของแต�ละคอลมน� --><table width="100%" border="1" style="border-collapse: collapse"> <tr> <td width="5%" bgcolor="black"><font face="MS Sans Serif" size="2"

color="white"><b>ร้หัส</b></font></td> <td width="20%" bgcolor="black"><font face="MS Sans Serif" size="2"

color="white"><b>ช้��อ</b></font></td> <td width="15%" bgcolor="black"><font face="MS Sans Serif" size="2"

color="white"><b>ที่!�อยู่#�</b></font></td> <td width="10%" bgcolor="black"><font face="MS Sans Serif" size="2"

color="white"><b>โที่ร้ศัพที่�</b></font></td> <td width="20%" bgcolor="black"><font face="MS Sans Serif" size="2"

color="white"><b>E-mail</b></font></td> <td width="30%" bgcolor="black"><font face="MS Sans Serif" size="2"

color="white"><b>โอมเพจ</b></font></td> </tr>

31

XSLT, larger font, 2 of 2<!-- เร้��มต�นอ�านข�อม#ลจากแหัล�งข�อม#ล 02-01_With_XSL.xml โดยู่การ้วนล#ป --><xsl:for-each select="myfriend/people"> <tr> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="id"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="name"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="address"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="telephone"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="email"/></font></td> <td><font face="MS Sans Serif" size="2"><xsl:value-of select="url"/></font></td> </tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>

32

XML in IE

33

Experiments• Install XMLSPY 5 Enterprise Edition

• Follow the online tutorial:

• Step I: making XML schema

• Step II: making XML file

• Step III: making XSLT