Sw Chapter - XML - V2

download Sw Chapter - XML - V2

of 114

Transcript of Sw Chapter - XML - V2

  • 8/2/2019 Sw Chapter - XML - V2

    1/114

    eXtensible Markup Language (XML)

  • 8/2/2019 Sw Chapter - XML - V2

    2/114

    Introduction to the Semantic WebXML2

    An HTML Example

    Nonmonotonic Reasoning: Context-

    Dependent Reasoningby V. Marek and

    M. Truszczynski

    Springer 1993
    ISBN 0387976892

  • 8/2/2019 Sw Chapter - XML - V2

    3/114

    Introduction to the Semantic Web3

    The Same Example in XML

    Nonmonotonic Reasoning: Context-Dependent Reasoning

    V. Marek

    M. Truszczynski

    Springer

    1993

    0387976892

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    4/114

    Introduction to the Semantic Web4

    HTML versus XML: Similarities

    Both use tags (e.g. and )

    Tags may be nested (tags within tags) Human users can read and interpret both

    HTML and XML representations quite easily

    But how about machines?

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    5/114

    Introduction to the Semantic Web5

    Problems with Automated

    Interpretation of HTML Documents

    An intelligent agent trying to retrieve the namesof the authors of the book

    Authors names could appear immediatelyafter the titleor immediately after the word by

    Are there two authors Or just one, called V.

    Marek and M. Truszczynski?

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    6/114

    Introduction to the Semantic Web6

    HTML vs XML: Structural Information

    HTML documents do not contain structuralinformation: pieces of the document and their

    relationships.

    XML more easily accessible to machines because

    Every piece of information is described.

    Relations are also defined through the nesting structure.

    E.g., the tags appear within the tags, sothey describe properties of the particular book.

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    7/114

    Introduction to the Semantic Web7

    HTML vs XML: Structural Information (2)

    A machine processing the XML document

    would be able to deduce that the author element refers to the enclosing book

    element rather than by proximity considerations

    XML allows the definition of constraints on

    values E.g. a year must be a number of four digits

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    8/114

    Introduction to the Semantic Web8

    HTML vs XML: Formatting

    The HTML representation provides more

    than the XML representation: The formatting of the document is also described

    But a weakness of HTML

    he main use of an HTML document is to

    display information: it must define formatting XML: separation of content from display

    same information can be displayed in differentways

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    9/114

    Introduction to the Semantic Web9

    HTML vs XML: Another Example

    In HTMLRelationship force-mass

    F = M a In XML

    Relationship force-mass

    F M a

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    10/114

    Introduction to the Semantic Web10

    HTML vs XML: Different Use of Tags

    Both previous HTML docs use same tags

    While XML use completely different tags

    HTML tags define display: color, lists

    XML tags not fixed: user definable tags

    XML meta markup language: language fordefining markups

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    11/114

    Introduction to the Semantic Web11

    XML Vocabularies

    Web applications must agree on common

    vocabularies to communicate and collaborate Communities and business sectors are

    defining their specialized vocabularies

    mathematics (MathML)

    bioinformatics (BSML)

    human resources (HRML)

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    12/114

    Introduction to the Semantic Web12

    Lecture Outline

    1. Introduction

    2. Detailed Description of XML3. Structuring

    a) DTDs

    b) XML Schema

    4. Namespaces5. Navigating XML documents: XPath

    6. Transformations: XSLT

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    13/114

    Introduction to the Semantic Web13

    Prolog of an XML Document

    The prolog consists of

    an XML declaration and an optional reference to external structuring

    documents

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    14/114

    Introduction to the Semantic Web14

    XML Elements

    The things the XML document talks about

    E.g. books, authors, publishers An element consists of:

    an opening tag

    the content

    a closing tag

    Shahid Waseem

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    15/114

    Introduction to the Semantic Web15

    XML Elements (2)

    Tag names can be chosen almost freely.

    The first character must be a letter, anunderscore, or a colon

    No name may begin with the string xml inany combination of cases

    E.g. Xml,xML

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    16/114

    Introduction to the Semantic Web16

    Content of XML Elements

    Content may be text, or other elements, or nothing

    Shahid Waseem +92 7 3875 507

    If there is no content, then the element is calledempty; it is abbreviated as follows: for

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    17/114

    Introduction to the Semantic Web17

    XML Attributes

    An empty element is not necessarily

    meaningless It may have some properties in terms of attributes

    An attribute is a name-value pair inside theopening tag of an element

  • 8/2/2019 Sw Chapter - XML - V2

    18/114

    Introduction to the Semantic Web18

    XML Attributes: An Example

  • 8/2/2019 Sw Chapter - XML - V2

    19/114

    Introduction to the Semantic Web19

    The Same Example without Attributes

    23456

    Mrs AkramOctober 15, 2011

    a5281

    c8173

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    20/114

    Introduction to the Semantic Web20

    XML Elements vs Attributes

    Attributes can be replaced by elements

    When to use elements and when attributes isa matter of taste

    But attributes cannot be nested

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    21/114

    Introduction to the Semantic Web21

    Well-Formed XML Documents

    Syntactically correct documents

    Some syntactic rules: Only one outermost element (called root element) Each element contains an opening and a

    corresponding closing tag

    Tags may not overlap Lee Hong

    Attributes within an element have unique names

    Element and tag names must be permissible

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    22/114

    Introduction to the Semantic Web22

    The Tree Model of XML Documents:

    An Example

    Semantic Web Lecture

    AoA, when is the next Semantic Web lecture and whichroom? Is there any assignment pending?

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    23/114

    Introduction to the Semantic Web23

    The Tree Model of XML Documents:

    An Example (2)

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    24/114

    Introduction to the Semantic Web24

    The Tree Model of XML Docs

    The tree representation of an XML documentis an ordered labeled tree:

    There is exactly one root

    There are no cycles

    Each non-root node has exactly one parent

    Each node has a label. The order of elements is important

    but the order of attributes is not important

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    25/114

    Introduction to the Semantic Web25

    Lecture Outline

    1. Introduction

    2.

    Detailed Description of XML3. Structuringa) DTDs

    b) XML Schema

    4. Namespaces5. Navigating XML documents: XPath

    6. Transformations: XSLT

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    26/114

    Introduction to the Semantic Web26

    Structuring XML Documents

    Define all the element and attribute namesthat may be used

    Define the structure

    what values an attribute may take

    which elements may or must occur within other

    elements, etc. If such structuring information exists, the

    document can be validated

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    27/114

    Introduction to the Semantic Web27

    Structuring XML Dcuments (2)

    An XML document is valid if

    it is well-formed respects the structuring information it uses

    There are two ways of defining the structureof XML documents:

    DTDs (the older and more restricted way) XML Schema (offers extended possibilities)

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    28/114

    Introduction to the Semantic Web28

    DTD: Element Type Definition

    David Billington

    +61 7 3875 507

    DTD for above element (and all lecturer elements)?

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    29/114

    Introduction to the Semantic Web29

    The Meaning of the DTD

    The element types lecturer, name, and phone maybe used in the document

    A lecturer element contains a name element and aphone element, in that order (sequence)

    A name element and a phone element may haveany content

    In DTDs, #PCDATA is the only atomic type forelements

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    30/114

    Introduction to the Semantic Web30

    DTD: Disjunction in Element Type

    Definitions

    We express that a lecturer element containseithera name element ora phone element asfollows:

    A lecturer element contains a name element

    and a phone element in any order.

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    31/114

    Introduction to the Semantic Web31

    Example of an XML Element

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    32/114

    Introduction to the Semantic Web32

    The Corresponding DTD

    customer CDATA #REQUIREDdate CDATA #REQUIRED>

    quantity CDATA #REQUIREDcomments CDATA #IMPLIED>

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    33/114

    Introduction to the Semantic Web33

    Comments on the DTD

    The item element type is defined to be empty

    + (after item) is a cardinality operator: ?: appears zero times or once

    *: appears zero or more times

    +: appears one or more times

    No cardinality operator means exactly once

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    34/114

    Introduction to the Semantic Web34

    Comments on the DTD (2)

    In addition to defining elements, we defineattributes

    This is done in an attribute list containing:

    Name of the element type to which the list applies

    A list of triplets of attribute name, attribute type,

    and value type Attribute name: A name that may be used in

    an XML document using a DTD

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    35/114

    Introduction to the Semantic Web35

    DTD: Attribute Types

    Similar to predefined data types, but limited selection

    The most important types are

    CDATA, a string (sequence of characters)

    ID, a name that is unique across the entire XML document

    IDREF, a reference to another element with an ID attributecarrying the same value as the IDREF attribute

    IDREFS, a series of IDREFs (v1| . . . |vn), an enumeration of all possible values

    Limitations: no dates, number ranges etc.

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    36/114

    Introduction to the Semantic Web36

    DTD: Attribute Value Types

    #REQUIRED

    Attribute must appear in every occurrence of the element

    type in the XML document

    #IMPLIED

    The appearance of the attribute is optional

    #FIXED "value"

    Every element must have this attribute

    "value"

    This specifies the default value for the attribute

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    37/114

    Introduction to the Semantic Web37

    Referencing with IDREF and IDREFS

    mother IDREF#IMPLIED

    father IDREF#IMPLIED

    children IDREFSXML

  • 8/2/2019 Sw Chapter - XML - V2

    38/114

    Introduction to the Semantic Web38

    An XML Document Respecting the DTD

    Kalsoom Yonus

    Muhammad Ali

    Khalida Yonus

    Muhammad Yonus

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    39/114

    Introduction to the Semantic Web

    XML Entities

    An XML entity can play the role as

    a placeholder for repeatable characters

    a section of external data

    a part of a declaration for elements

    We can use the entity reference &thisyearinstead ofthe value " 2007 "

    39 XML

  • 8/2/2019 Sw Chapter - XML - V2

    40/114

    Introduction to the Semantic Web40

    A DTD for an Email Element

    #IMPLIED

    address CDATA

    #REQUIRED>

    address CDATA#REQUIRED>XML

  • 8/2/2019 Sw Chapter - XML - V2

    41/114

    Introduction to the Semantic Web41

    A DTD for an Email Element (2)

    CDATA #IMPLIEDaddress CDATA#REQUIRED>

    encoding (mime|binhex)

    "mime" fileXML

  • 8/2/2019 Sw Chapter - XML - V2

    42/114

    Introduction to the Semantic Web42

    Interesting Parts of the DTD

    A head element contains (in that order):

    a from element

    at least one to element

    zero or more cc elements

    a subject element

    In from, to, and cc elements the name attribute is not required

    the address attribute is always required

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    43/114

    Introduction to the Semantic Web43

    Interesting Parts of the DTD (2)

    A body element contains

    a text element

    possibly followed by a number of attachmentelements

    The encoding attribute of an attachment

    element must have either the value mimeor binhex

    mime is the default value

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    44/114

    Introduction to the Semantic Web44

    Lecture Outline

    1. Introduction

    2. Detailed Description of XML

    3. Structuringa) DTDs

    b) XML Schema

    4. Namespaces5. Navigating XML documents: XPath

    6. Transformations: XSLT

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    45/114

    Introduction to the Semantic Web45

    XML Schema

    Significantly richer language for defining thestructure of XML documents

    Its syntax is based on XML itself not necessary to write separate tools

    Reuse and refinement of schemas

    Expand or delete already existent schemas Sophisticated set of data types, compared to

    DTDs (which only supports strings)

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    46/114

    Introduction to the Semantic WebXML46

    XML Schema (2)

    An XML schema is an element with an opening taglike

    Structure of schema elements

    Element and attribute types using data types

  • 8/2/2019 Sw Chapter - XML - V2

    47/114

    Introduction to the Semantic WebXML47

    Element Types

    Cardinality constraints:

    minOccurs="x" (default value 1) maxOccurs="x" (default value 1)

    Generalizations of *,?,+ offered by DTDs

  • 8/2/2019 Sw Chapter - XML - V2

    48/114

    Introduction to the Semantic WebXML48

    Attribute Types

    < attribute name="speaks" type="Language"

    use="default" value="en"/>

    Existence: use="x", where x may be

    optional or required Default value: use="x" value="...", where x

    may be default or fixed

  • 8/2/2019 Sw Chapter - XML - V2

    49/114

    Introduction to the Semantic WebXML49

    Data Types

    There is a variety of built-in data types

    Numerical data types: integer, Short etc.

    String types: string, ID, IDREF, CDATA etc.

    Date and time data types: time, Month etc.

    There are also user-defined data types

    simple data types, which cannot use elements orattributes

    complex data types, which can use elements or/andattributes

  • 8/2/2019 Sw Chapter - XML - V2

    50/114

    Introduction to the Semantic WebXML50

    Data Types (2)

    Complex data types are defined from already existing datatypes by defining some attributes (if any) and using indicators:

    Order indicators sequence, a sequence of existing data type elements (order is

    important)

    all, a collection of elements that must appear (order is notimportant)

    choice, a collection of elements, of which one will be chosen

    Occurrence Indicators maxOccurs

    minOccurs

  • 8/2/2019 Sw Chapter - XML - V2

    51/114

    Introduction to the Semantic Web

    An Example

    XML51

  • 8/2/2019 Sw Chapter - XML - V2

    52/114

    Introduction to the Semantic WebXML52

    A Data Type Example

  • 8/2/2019 Sw Chapter - XML - V2

    53/114

    Introduction to the Semantic WebXML53

    Data Type Extension

    Already existing data types can be extended by new elementsor attributes. Example:

  • 8/2/2019 Sw Chapter - XML - V2

    54/114

    Introduction to the Semantic WebXML54

    Resulting Data Type

  • 8/2/2019 Sw Chapter - XML - V2

    55/114

    Introduction to the Semantic WebXML55

    Data Type Extension (2)

    A hierarchical relationship exists between theoriginal and the extended type

    Instances of the extended type are also instancesof the original type

    They may contain additional information, butneither less information, nor information of thewrong type

  • 8/2/2019 Sw Chapter - XML - V2

    56/114

    Introduction to the Semantic WebXML56

    Data Type Restriction

    An existing data type may be restricted by addingconstraints on certain values

    Restriction is not the opposite from extension Restriction is not achieved by deleting elements or attributes

    The following hierarchical relationship still holds:

    Instances of the restricted type are also instances of the

    original type They satisfy at least the constraints of the original type

  • 8/2/2019 Sw Chapter - XML - V2

    57/114

    Introduction to the Semantic Web

    Mixed Content Example

    Dear Mr.John Smith.

    Your order 1032

    will be shipped on 2001-07-13.

    XML57

  • 8/2/2019 Sw Chapter - XML - V2

    58/114

    Introduction to the Semantic WebXML58

    Example of Data Type Restriction

  • 8/2/2019 Sw Chapter - XML - V2

    59/114

    Introduction to the Semantic WebXML59

    Restriction of Simple Data Types

  • 8/2/2019 Sw Chapter - XML - V2

    60/114

    Introduction to the Semantic WebXML60

    Data Type Restriction: Enumeration

  • 8/2/2019 Sw Chapter - XML - V2

    61/114

    Introduction to the Semantic WebXML61

    XML Schema: The Email Example

  • 8/2/2019 Sw Chapter - XML - V2

    62/114

    Introduction to the Semantic WebXML62

    XML Schema: The Email Example (2)

  • 8/2/2019 Sw Chapter - XML - V2

    63/114

    Introduction to the Semantic WebXML63

    XML Schema: The Email Example (3)

    Similar for bodyType

  • 8/2/2019 Sw Chapter - XML - V2

    64/114

    Introduction to the Semantic WebXML64

    Lecture Outline

    1. Introduction

    2. Detailed Description of XML

    3. Structuringa) DTDs

    b) XML Schema

    4. Namespaces5. Navigating XML documents: XPath

    6. Transformations: XSLT

  • 8/2/2019 Sw Chapter - XML - V2

    65/114

    Introduction to the Semantic WebXML65

    Namespaces

    An XML document may use more than oneDTD or schema

    Since each structuring document wasdeveloped independently, name clashes mayappear

    The solution is to use a different prefix foreach DTD or schema

    prefix:name

  • 8/2/2019 Sw Chapter - XML - V2

    66/114

    Introduction to the Semantic WebXML66

    An Example

  • 8/2/2019 Sw Chapter - XML - V2

    67/114

    Introduction to the Semantic WebXML67

    Namespace Declarations

    Namespaces are declared within an elementand can be used in that element and any ofits children (elements and attributes)

    A namespace declaration has the form:

    xmlns:prefix="location"

    location is the address of the DTD or schema If a prefix is not specified: xmlns="location"

    then the location is used by default

  • 8/2/2019 Sw Chapter - XML - V2

    68/114

    Introduction to the Semantic WebXML68

    Lecture Outline

    1. Introduction

    2. Detailed Description of XML

    3. Structuringa) DTDs

    b) XML Schema

    4. Namespaces5. Navigating XML documents: XPath

    6. Transformations: XSLT

  • 8/2/2019 Sw Chapter - XML - V2

    69/114

    Introduction to the Semantic WebXML69

    Addressing and Querying XML

    Documents

    In relational databases, parts of a databasecan be selected and retrieved using SQL Same necessary for XML documents Query languages: XQuery, XQL, XML-QL

    The central concept of XML query languagesis a path expression

  • 8/2/2019 Sw Chapter - XML - V2

    70/114

    Introduction to the Semantic WebXML70

    XPath

    XPath is core for XML query languages

    Language for addressing parts of an XMLdocument.

    It operates on the tree data model of XML

    It specifies how a node or a set of nodes, in the

    tree representation of the XML document can bereached

    It has a non-XML syntax

  • 8/2/2019 Sw Chapter - XML - V2

    71/114

    Introduction to the Semantic Web

    Tree Structure of an XML Document

    The root node

    Element nodes

    Text nodes

    Attribute nodes

    Comment nodes

    Processing-instruction nodes

    Namespace nodes

    XML71

  • 8/2/2019 Sw Chapter - XML - V2

    72/114

    Introduction to the Semantic Web

    Tree Structure of an XML Document (II)

    XML72

  • 8/2/2019 Sw Chapter - XML - V2

    73/114

    Introduction to the Semantic WebXML73

    Types of Path Expressions

    Absolute (starting at the root of the tree)

    Syntactically they begin with the symbol /

    It refers to the root of the document (situated onelevel above the root element of the document)

    Relative to a context node

  • 8/2/2019 Sw Chapter - XML - V2

    74/114

    Introduction to the Semantic WebXML74

    An XML Example

  • 8/2/2019 Sw Chapter - XML - V2

    75/114

    Introduction to the Semantic WebXML75

    Tree Representation

    Anything

    missing ??

  • 8/2/2019 Sw Chapter - XML - V2

    76/114

    Introduction to the Semantic WebXML76

    Examples of Path Expressions in

    XPath

    Address all author elements

    /library/author

    Addresses all author elements that arechildren of the library element node, whichresides immediately below the root.

    EditiX also shows the attributes of elements

    /t1/.../tn, where each ti+1 is a child node ofti, is a path through the tree representation

  • 8/2/2019 Sw Chapter - XML - V2

    77/114

    Introduction to the Semantic WebXML77

    General Form of Path Expressions

    A path expression consists of one or more steps, each steprepresents an individual location path and is separated by a

    / (slash)

    An absolute location path:/step/step/...

    A relative location path:step/step/...

    Each step is evaluated against the nodes in the current node-set

  • 8/2/2019 Sw Chapter - XML - V2

    78/114

    Introduction to the Semantic WebXML78

    Examples of Path Expressions in

    XPath (2)

    Address all author elements anywhere inthe document

    //author

    Here // says that we should consider allelements in the document and check

    whether they are of type author

  • 8/2/2019 Sw Chapter - XML - V2

    79/114

    Introduction to the Semantic WebXML79

    Examples of Path Expressions in

    XPath (3)

    Address the location attribute nodes withinlibrary element nodes

    /library/@location

    The symbol @ is used to denote attributenodes

  • 8/2/2019 Sw Chapter - XML - V2

    80/114

    Introduction to the Semantic WebXML80

    Examples of Path Expressions in

    XPath (4)

    Address all title attribute nodes within bookelements anywhere in the document, which

    have the value Artificial Intelligence

    //book/@title= "Artificial Intelligence

    Addressed node is an attribute, therefore theresult is a Boolean value

  • 8/2/2019 Sw Chapter - XML - V2

    81/114

    Introduction to the Semantic WebXML81

    Examples of Path Expressions in

    XPath (5)

    Address all books with title Artificial Intelligence

    //book[@title="Artificial Intelligence"]

    Test within square brackets: a predicate (or filterexpression)

    It restricts the set of addressed nodes.

    Query 4 addresses book elements, the title of whichsatisfies a certain condition.

  • 8/2/2019 Sw Chapter - XML - V2

    82/114

    Introduction to the Semantic WebXML82

    Tree Representation of Query 4

  • 8/2/2019 Sw Chapter - XML - V2

    83/114

    Introduction to the Semantic WebXML83

    Tree Representation of Query 5

  • 8/2/2019 Sw Chapter - XML - V2

    84/114

    Introduction to the Semantic WebXML84

    Examples of Filter Expressions

    (Predicates)

    Address the first author element node in the XML document

    //author[1]

    Address the title of last book element within the first author elementnode in the document

    //author[1]/book[last()]/@title

    Address the title of all book elements having price greater than 30

    //book[@price>30]/@title

    Address all book element nodes without a title attribute

    //book[not @title]

  • 8/2/2019 Sw Chapter - XML - V2

    85/114

    Introduction to the Semantic WebXML85

    Few more Queries

    Selecting several paths: gives the name of all authors and thetitles of their books

    //author/@name | //book/@title

    Returns the attribute values of title and price of all bookelements

    //book/@title | //book/@price

    Path expression with wildcard: selects all the elements in thedocument

    //*

  • 8/2/2019 Sw Chapter - XML - V2

    86/114

    Introduction to the Semantic Web

    Xpath Usage XPath is a major element in W3C's XSLT standard - and

    XQuery and XPointer are both built on XPath expressions

    XML86

  • 8/2/2019 Sw Chapter - XML - V2

    87/114

    Introduction to the Semantic Web

    XPath Summary

    Xpath is for finding information in an XML document bynavigating through elements and attributes in the XML

    document.

    Its adoption has been widespread within other XMLstandards.

    XML87

  • 8/2/2019 Sw Chapter - XML - V2

    88/114

    Introduction to the Semantic WebXML88

    Lecture Outline

    1. Introduction

    2. Detailed Description of XML

    3. Structuringa) DTDs

    b) XML Schema

    4.

    Namespaces5. Navigating XML documents: XPath

    6. Transformations: XSLT

  • 8/2/2019 Sw Chapter - XML - V2

    89/114

    Introduction to the Semantic WebXML89

    Displaying XML Documents

    Grigoris Antoniou

    University of [email protected]

    may be displayed in different ways:

    Grigoris Antoniou Grigoris AntoniouUniversity of Bremen University of Bremen

    [email protected] [email protected]

  • 8/2/2019 Sw Chapter - XML - V2

    90/114

    Introduction to the Semantic WebXML90

    Style Sheets

    Style sheets can be written in variouslanguages

    E.g. CSS2 (cascading style sheets level 2)

    XSL (extensible stylesheet language)

    XSL includes

    a transformation language (XSLT) a formatting language (XSL-FO)

    Both are XML applications

  • 8/2/2019 Sw Chapter - XML - V2

    91/114

    Introduction to the Semantic Web

    Styling a Document

    XML91

    Practical Examples of Style Sheets in Use

  • 8/2/2019 Sw Chapter - XML - V2

    92/114

    Introduction to the Semantic WebXML92

  • 8/2/2019 Sw Chapter - XML - V2

    93/114

    Introduction to the Semantic WebXML93

    XSL Transformations (XSLT)

    XSLT specifies rules with which an input XMLdocument is transformed to

    another XML document an HTML document

    plain text

    The output document may use the same DTD or

    schema, or a completely different vocabulary XSLT can be used independently of the formatting

    language

  • 8/2/2019 Sw Chapter - XML - V2

    94/114

    Introduction to the Semantic WebXML94

    XSLT (2)

    Move data and metadata from one XMLrepresentation to another

    XSLT is chosen when applications that use differentDTDs or schemas need to communicate

    XSLT can be used for machine processing of contentwithout any regard to displaying the information for

    people to read. In the following we use XSLT only to

    transform/display XML documents in HTML

  • 8/2/2019 Sw Chapter - XML - V2

    95/114

    Introduction to the Semantic WebXML95

    XSLT Transformation into HTML

    Grigoris Antoniou

    University of Bremen

    [email protected]

  • 8/2/2019 Sw Chapter - XML - V2

    96/114

    Introduction to the Semantic WebXML

    96

    Style Sheet Output

    An author

    Grigoris Antoniou

    University of Bremen

    [email protected]

  • 8/2/2019 Sw Chapter - XML - V2

    97/114

    Introduction to the Semantic WebXML

    97

    Observations About XSLT

    XSLT documents are XML documents XSLT resides on top of XML

    The XSLT document defines a template In this case an HTML document, with some

    placeholders for content to be inserted

    xsl:value-of retrieves the value of an

    element and copies it into the outputdocument It places some content into the template

  • 8/2/2019 Sw Chapter - XML - V2

    98/114

    Introduction to the Semantic WebXML

    98

    A Template

    An author

    ...

    ...

    ...

  • 8/2/2019 Sw Chapter - XML - V2

    99/114

    Introduction to the Semantic WebXML

    99

    Auxiliary Templates

    We have an XML document with details ofseveral authors

    It is a waste of effort to treat each authorelement separately

    In such cases, a special template is defined for

    author elements, which is used by the maintemplate

  • 8/2/2019 Sw Chapter - XML - V2

    100/114

    Introduction to the Semantic Web

    100

    Example of an Auxiliary Template

    Grigoris Antoniou

    University of [email protected]

    David Billington

    Griffith [email protected]

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    101/114

    Introduction to the Semantic Web

    101

    Example of an Auxiliary Template (2)

    Authors

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    102/114

    Introduction to the Semantic Web

    102

    Example of an Auxiliary Template (3)

    Affiliation:

    Email:

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    103/114

    Introduction to the Semantic Web

    103

    Multiple Authors Output

    Authors

    Grigoris AntoniouAffiliation: University of Bremen
    Email: [email protected]

    David BillingtonAffiliation: Griffith University

    Email: [email protected]

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    104/114

    Introduction to the Semantic Web

    104

    Explanation of the Example

    xsl:apply-templates element causes all children ofthe context node to be matched against the selected

    path expression E.g., if the current template applies to /, then the element

    xsl:apply-templates applies to the root element i.e. theauthors element (/ is located above the root element)

    If the current context node is the authors element, then the

    element xsl:apply-templates select="author" causes thetemplate for the author elements to be applied to all authorchildren of the authors element

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    105/114

    Introduction to the Semantic Web

    105

    Explanation of the Example (2)

    It is good practice to define a template foreach element type in the document

    Even if no specific processing is applied to certainelements, the xsl:apply-templates elementshould be used

    E.g. authors

    In this way, we work from the root to theleaves of the tree, and all templates areapplied

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    106/114

    Introduction to the Semantic Web

    106

    Processing XML Attributes

    Suppose we wish to transform to itself the element:

    Wrong solution:

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    107/114

    Introduction to the Semantic Web

    107

    Processing XML Attributes (2)

    Not well-formed because tags are notallowed within the values of attributes

    We wish to add attribute values into template

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    108/114

    Introduction to the Semantic Web

    108

    Transforming an XML Document toAnother

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    109/114

    Introduction to the Semantic Web

    109

    Transforming an XML Document toAnother (2)

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    110/114

    Introduction to the Semantic Web

    110

    Transforming an XML Document toAnother (3)

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    111/114

    Introduction to the Semantic Web

    Show Another Example

    XML

    111

  • 8/2/2019 Sw Chapter - XML - V2

    112/114

    Introduction to the Semantic Web

    112

    XML Chapters Summary

    XML is a metalanguage that allows users to define markup.

    Nesting of tags introduces structure. The structure of documentscan be enforced using schemas or DTDs.

    XML separates content and structure from formatting.

    XML is the de facto standard for the representation and exchangeof structured information on the Web.

    XML supports the exchange of structured information across

    different applications through markup, structure, andtransformations.

    XML is supported by query languages

    XML

    S

  • 8/2/2019 Sw Chapter - XML - V2

    113/114

    Introduction to the Semantic Web

    113

    Points for Discussion in SubsequentChapters

    The nesting of tags does not have standard meaning

    The semantics of XML documents is not accessible tomachines, only to people

    Collaboration and exchange are supported if there is underlyingshared understanding of the vocabulary

    XML is well-suited for close collaboration, where domain- orcommunity-based vocabularies are used

    It is not so well-suited for global communication.

    XML

  • 8/2/2019 Sw Chapter - XML - V2

    114/114

    XML Assignment 2

    Has Arrived