Session Number: 5 - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Session Number: 5

Description:

If you want to use style sheets, you have to tell the browser where to find the ... street ORDER='1' 123 Lumpkin Lane /street street ORDER='2' Apt 1B /street ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 34
Provided by: ellise
Category:
Tags: number | session

less

Transcript and Presenter's Notes

Title: Session Number: 5


1
Internet Supply Chain Management ECT 581
Winter 2003
Session Number 5
  • Session Date February 4, 2003
  • Session Outline
  • Administrative Items
  • Session Topics XML (continued)
  • XML Defined
  • XML as a Content Development Tool

2
Session Number 5
  • Session Date February 5, 2002
  • Session Topics
  • XML (continued)
  • Session Outline
  • Administrative Items
  • Session Material

3
Administrative Items
  • Web Site Updates
  • Initial Exam Homework Results
  • Project Information
  • Homework Assignment 2

4
XML Development - The Basics
  • Include an XML declaration as the first
    statement in an XML document.
  • One tag (the root element) contains all of the
    other tags.
  • Every element must have a start and an end tag.
  • Empty elements must end in /gt
  • (Empty elements do not hold content between the
    start and end tags)
  • Nesting of tags follow the LIFO rule last tag
    defined is the first tag closed.
  • All attribute values are closed in quotes.
  • Tags and entities always begin the same way.
  • Tags begin with less than (lt) sign.
  • Entities begin with an ampersand () sign.

5
XML Essentials DTD Composition
  • DTDs consist of the following
  • XML declaration tells the processor which
    version of XML to use.
  • Document type declaration Tell the processor
    where the DTD is located.
  • Element type declaration Defines the element
    type.
  • Attribute list declaration defines the name,
    data type, and default value (if any) of each
    attribute associated with an element.
  • Entity declaration defines a set of
    information that can be called by using its
    entity name.
  • Notation declaration associates a notation
    name with information that can help find an
    interpreter of the notation.

6
XML Entities (continued) Parameter Entity
Example
lt!- Segment from sample Order Form DTD -gt lt!-
Document Structure -gt lt!ELEMENT order (addresses,
lineitems, payment)gt . . lt!- Payment Structure
-gt lt!ELEMENT payment (card PO)gt . .lt!- Card
Structure -gt lt!ELEMENT card (cardholder, number,
expiration)gt lt!ELEMENT cardholder
(PCDATA)gt lt!ELEMENT number (PCDATA)gt lt!ELEMENT
expiration (PCDATA)gt . . lt!- Attribute Rules
-gt lt!ATTLIST card CARDTYPE (VISA Mastercard
Amex) REQUIREDgt
CARDTYPE might show up later in the document as
follows . . ltpaymentgt ltcard
CARDTYPEVISAgt ltcardholdergtJoe
Blowlt/cardholdergt ltnumbergt41280000000000lt/
numbergt ltexpirationgt01/03lt/expirationgt
lt/cardgt lt/paymentgt . . lt/ordergt
7
XML Entities
  • In general, an entity is used like an
    abbreviation.
  • Entities are primarily structural elements.
  • Whereas elements attributes enable
    specification of logical meaning.
  • Associates an entity name with a content
    fragment.
  • Four types
  • Internal parsed allows definition of an alias
    for text fragment.
  • External parsed enables inclusion of an entire
    file as part of a document.
  • Unparsed enables insertion of arbitrary data
    into a document.
  • Parameter enables creation of reusable and
    extensible design elements in a DTD.

8
XML An Example (reprise)
  • Using the recipe example, we can create the
    foundation of a DTD.

lt!DOCTYPE recipe lt!ELEMENT recipe (title,
ingredients, directions, body)gt lt!ELEMENT Title
(PCCHAR) lt!ELEMENT ingredients (ingred_amt,
ingred)gt lt!ELEMENT ingred_amt
(PCDATA)gt lt!ELEMENT ingred
(PCDATA)gt lt!ELEMENT directions (mix_instr,
cook_instr, method)gt lt!ELEMENT mix_instr
(PCDATA)gt lt!ELEMENT cook_instr
(PCDATA)gt lt!ELEMENT method
(PCDATA)gt lt!ENTITY wig Wow! Its good so easy
to make!gt gt ltrecipegt lttitlegtDoughlt/titlegt
ltingredientsgt ltingred_amt
gt1 cuplt/ingred_amtgt ltingredgtflourlt/ingredgt
ltingred_amtgt1
tsp.lt/ingred_amtgt ltingredgtsaltlt/ingredgt .
(etc.) lt/recipegt
9
XML Options for Displaying XML
10
Displaying an XML Document Cascading Style
Sheets (CSS)
  • Basic Steps for creating CSS
  • Create the style sheet.
  • Link the style sheet to the XML document.
  • If you want to use style sheets, you have to
    tell the browser where to find the stylesheet
    with a statement looking something like this
  • lt?xml-stylesheet hrefa_stylesheet.css"
    type"text/css" ?gt

11
CSS Example Create the CSS
  • Create a file in a text editor (i.e., Notepad,
    WordPad, MS Word, or some other editor)
  • For example
  • / File Name Memo.css /
  • TITLE displayblock margin-top12pt
    font-size10pt
  • SUBJECT font-styleitalic
  • TO font-weightbold
  • FROM font-weightbold
  • This initial CSS can be applied to the initial
    XML Memo Document.

12
CSS Example Updated XML Memo Document
lt?xml version"1.0"?gt lt!-- File Name Memo01.xml
--gt lt?xml-stylesheet type"text/css"
href"Memo01.css"?gt lt!DOCTYPE MEMO lt!ELEMENT
MEMO (TITLE, TO, FROM, SUBJECT, BODY, CLOSING,
SIGNATURE)gt lt!ELEMENT TITLE (PCDATA)gt lt!ELEMEN
T TO (PCDATA)gt lt!ELEMENT FROM (PCDATA)gt lt!ELEM
ENT SUBJECT (PCDATA)gt lt!ELEMENT
BODY (PCDATA)gt lt!ELEMENT CLOSING
(PCDATA)gt lt!ELEMENT SIGNATURE
(PCDATA)gt lt!ENTITY to "To "gt lt!ENTITY fm "From
"gt lt!ENTITY sub "Subject "gt lt!ENTITY cls
"Sincerely, "gt gt
ltMEMOgt ltTITLEgtClass Memorandumlt/TITLEgt ltTOgtto
ECT 581 Studentslt/TOgt ltFROMgtfm Ellis
Conferlt/FROMgt ltSUBJECTgtsub My
Errorlt/SUBJECTgt ltBODYgt Somehow, I accidentally
deleted the TITLE element from the DTD example
tags from the original version of this XML
example. It is fixed now. Now we can proceed
with the rest of the lesson. lt/BODYgt ltCLOSINGgtcls
lt/CLOSINGgt ltSIGNATUREgtEllis Conferlt/SIGNATUREgt lt/
MEMOgt
13
CSS Example Create the CSS (continued)
  • Lets look at a more advanced CSS applied to the
    updated XML Memo document.
  • / File Name Memo01.css /
  • TITLE
  • color white font-size 14pt
    font-family "Times New Roman" background
    maroon right display block margin-top 12pt
  • SUBJECT
  • font 18pt "Times New Roman" display
    block margin-top 12pt
  • TO
  • font-weight bold display
    blockmargin-top 12pt
  • FROM
  • font-weightbold display block
  • BODY font 12pt "Times New Roman" display
    block margin-top 12pt
  • CLOSING font 12pt "Times New Roman" display
    block margin-top 12pt
  • SIGNATURE font 12pt "Times New Roman"
    display block margin-top 24pt

14
XSL (Extensible Style Language)
  • XSL is a language for expressing XML display
    formatting stylesheets.
  • It consists of two parts
  • 1. a language for transforming XML documents (XSL
    Transformation or XSLT), and
  • 2. an XML vocabulary for specifying formatting
    semantics.
  • XSLT is a language for transforming XML documents
    into other XML documents.
  • An XSL stylesheet specifies the presentation of a
    class of XML documents by describing how an
    instance of the class is transformed into an XML
    document that uses the formatting vocabulary.

15
XSL (continued) Components of XSL Language
  • The full XSL language logically consists of three
    component languages
  • XPath XML Path Language--a language for
    referencing specific parts of an XML document.
  • XSLT XSL Transformations--a language for
    describing how to transform one XML document
    (represented as a tree) into another.
  • XSL Extensible Stylesheet Language--XSLT plus a
    description of a set of Formatting Objects and
    Formatting Properties.
  • described in three W3C (World Wide Web
    Consortium) Recommendations

16
XSL (continued) Basically, what does a
Stylesheet do?
  • A stylesheet specifies the presentation of XML
    information using two basic categories of
    techniques
  • An optional transformation of the input document
    into another structure.
  • A description of how to present the transformed
    information (i.e., a specification of what
    properties to associate to each of the various
    parts of the transformed information).


17
XSL (continued) - Basically, what makes up a
Stylesheet?
  • An XSL stylesheet basically consists of a set of
    templates
  • Each template "matches" some set of elements in
    the source tree and then describes the
    contribution that the matched element makes to
    the result tree.
  • Generally, elements in a stylesheet in the "xsl"
    namespace are part of the XSL transformation
    (XSLT) language, and non-xsl elements within a
    template are what get put into the result tree.

18
XSL (continued) Description of Info in an XML
Document
  • Description of how to present the (possibly
    transformed) data includes three levels of
    formatting information
  • Specification of the general screen or page (or
    even audio) layout.
  • Note, XSL is usable with different display
    technologies (i.e., HTML, PDF, Postscript).
  • Assignment of the transformed content into basic
    "content container types" (e.g., lists,
    paragraphs, inline text)
  • Specification of formatting properties (spacing,
    margins, alignment, fonts, etc.) for each
    resulting "container"

19
XSL (continued) Transformation Capabilities
  • Transformation capabilities include
  • generation of constant text
  • suppression of content
  • moving text (e.g., exchanging the order of the
    first and last name)
  • duplicating text (e.g., copying titles to make a
    table of contents)
  • Sorting
  • more complex transformations that "compute" new
    information in terms of the existing information

20
What is XSLT?
  • XSLT, a subset of XSL, transforms an XML
    document in one format to an XML document in
    another format.
  • Responds to the issue of info exchange between
    different organizational entities.
  • Manifests as an XSLT transformation document
    which is also an XML document.
  • Transformation document resolves differences
    between DTDs.

21
What is XSLT? (continued)
An XSLT "stylesheet" transforms the input
(source) document's tree into a structure called
a result tree consisting of result objects.
22
What is XSLT? (continued)
Example where two different organizations show
parts of order documents in 2 different formats.
XSLT code will perform the transformation.
Document 2 Order currency models currency info
as a child element of the order element ltorder
currencygt ltcurrencygtUSDlt/currencygt ... lt/ordergt
Document 1 Order currency shown as an attribute
on the order element ltorder
currencyUSDgt lt/ordergt
ltxsltemplate match/gt ltxslfor-each
selectordergt ltordergt ltcurrencygt
ltxslvalue-of-select_at_currency/gt
lt/currencygt lt/ordergt ltxslfor-eachgt lt/xslte
mplategt
XSLT transformation document designed to resolve
differences between docs 12.
23
XSLT Example Document as Stylesheet
Simple stylesheet transforms source ltparagt and
ltemphasisgt elements into HTML
STYLESHEET lt?xml version'1.0'?gt ltxslstylesheet
xmlnsxsl"http//www.w3.org/1999/XSL/Transform"
version"1.0"gt ltxsltemplate match"para"gt
ltpgtltxslapply-templates/gtlt/pgt lt/xsltemplategt
ltxsltemplate match"emphasis"gt
ltigtltxslapply-templates/gtlt/igt lt/xsltemplategt
lt/xslstylesheetgt
With STYLESHEET, the following XML
document lt?xml version'1.0'?gt ltparagtThis is a
ltemphasisgttestlt/emphasisgt.lt/paragt Would be
transformed into lt?xml version"1.0"
encoding"utf-8"?gt ltpgtThis is a ltigttestlt/igt.lt/pgt
24
XSL (continued)
  • XSL stylesheets consist of 5 major components
  • construction rules - these locate elements in the
    document with defined patterns and results or
    actions.
  • style rules - these assign characteristics to
    elements in the source document.
  • named styles - these define a name for a
    collection of characteristics.
  • macros -these define an object with clear
    parameters.
  • scripts - these calculate results for use in a
    style attachment.

25
XSL (continued) Using XSL
  • Basic Steps for using an XSL stylesheet
  • Create the XSL style sheet file.
  • Link the XSL style sheet file to the XML
    document.
  • If you want to use XSL style sheets, you have to
    tell the browser where to find the stylesheet
    with a statement looking something like this
  • lt?xml-stylesheet typetext/xsl
    hrefXSLFilePath?gt
  • where XSLFilePath is a quoted URL
    indicating the location of the style sheet
    file.
  • Note the style sheet file will typically be
    stored in the folder where the xml document
    resides or in one of its subfolders.

26
XSL Example Document as Stylesheet
lthtml xmlnsxsl"http//www.w3.org/1999/XSL/Trans
form"gt ltheadgt lttitlegtSilly Examplelt/titlegt
lt/headgt ltbodygt lth1gtSilly Examplelt/h1gt ltpgtYou'd
probably use extension elements, or something
more interesting in real life 34 is
ltxslvalue-of select"34"/gt. lt/pgt lt/bodygt
lt/htmlgt
27
XSL Example Order Form
lt?xml version1.0gt ltDOCTYPE order SYSTEM
MUSICORDER.DTDgt lt!--Example Order Form for EC
Music Madness--gt lt?xml-stylesheet typetext/xsl
hrefxsldemo.xsl?gt ltorder SOURCEweb
CUSTOMERTYPECONSUMER CURRENCYUSDgt
ltaddressesgt ltaddress ADDTYPEbillshipgt ltfirst
namegtJohnlt/firstnamegt ltlastnamegtSmithlt/lastnamegt
ltstreet ORDER1gt123 Lumpkin
Lanelt/streetgt ltstreet ORDER2gtApt
1Blt/streetgt ltcitygtJohnson Citylt/citygt ltstategtP
Alt/stategt . lt/addressesgt ltlineitemsgt
. . lt/lineitemsgt . . ltpayment
. lt/paymentgt ltordergt
Example of an abbreviated XML-based order form.
28
XSL Example Order Form (continued)
ltxsltemplate matchaddressgt ltfoblock
fofont-sizelarge fofont-weightbold
fofont-familyTimes New Roman
foline-height2 ltxslapply-template/gt lt/fo
blockgt lt/xsltemplategt ltxsltemplate
matchaddress_at_ADDTYPEshipgtgt ltfoblock
fofont-sizesmall fofont-weightnormal
fofont-familyTimes foline-height1
ltxslapply-template/gt lt/foblockgt lt/xsltemplategt
. . .
xsldemo stylesheet (abbreviated version) can be
applied to affect the display of specific
elements.
Note fo refers to formatting object. For more
info please refer to the following
link http//www.w3.org/TR/xsl/slice6.htmlfo-sect
ion
29
XML Namespaces
  • XML namespaces are designed to provide
    universally unique names for elements and
    attributes. This allows people to do a number of
    things, such as
  • Combine portions from different documents and,
    thereby, avoid any naming conflicts.
  • Write code modules that can be invoked for
    specific elements and attributes.
  • Define elements and attributes that can be
    reused in other schemas or instance documents
    without fear of name collisions.
  • The XML namespaces defines a way to distinguish
    between duplicate element type and attribute
    names.

30
XML Namespaces (continued)
  • Example accounting fulfillment application
    both want to use status as a keyword.
  • Attaching namespace to an element or attribute
    name links it with namespace.
  • Namespace names for department can be declared
  • ltacctcustomer xmlnsaccthttp///www.blahcompany.
    com/names/acct-deptstdsgt
  • ltacctnamegtFriendly Corplt/acctnamegt
  • ltacctaddresseegtltAccounts Payable-Friendly
    Corplt/acctaddresseegt
  • ltacctorder acctreference2222-1001gt
  • ltacctstatusgtinvoicelt/acctstatusgt
  • lt /acctordergt
  • lt/acctcustomergt
  • ltfulcustomer xmlnsfulhttp///www.blahcompany.co
    m/names/ful-deptstdsgt
  • ltfulnamegtFriendly Corplt/fulnamegt
  • ltfuladdresseegtltLoading Docklt/fuladdresseegt
  • ltacctorder acctreference2222-1001gt
  • ltfulstatusgtshippedlt/fulstatusgt
  • lt /fulordergt
  • lt/fulcustomergt

31
XML Namespaces Five Bullets
  • The XML namespaces recommendation defines a way
    to distinguish between duplicate element type and
    attribute names. Such duplication might occur,
    for example, in an XSLT stylesheet or in a
    document that contains element types and
    attributes from two different DTDs.
  • An XML namespace is a collection of element type
    and attribute names. The namespace is identified
    by a unique name, which is a URI. Thus, any
    element type or attribute name in an XML
    namespace can be uniquely identified by a
    two-part name the name of its XML namespace and
    its local name. This two-part naming system is
    the only thing defined by the XML namespaces
    recommendation.
  • XML namespaces are declared with an xmlns
    attribute, which can associate a prefix with the
    namespace. The declaration is in scope for the
    element containing the attribute and all its
    descendants. For example
  • lt!-- Declares two XML namespaces. Their scope is
    the A and B elements. --gt ltA xmlnsfoo"http//www
    .foo.org/" xmlns"http//www.bar.org/"gt
    ltBgtabcdlt/Bgt lt/Agt

32
XML Namespaces Five Bullets (continued)
  • If an XML namespace declaration contains a
    prefix, you refer to element type and attribute
    names in that namespace with the prefix. For
    example
  • lt!-- A and B are in the http//www.foo.org/
    namespace, which is associated with the foo
    prefix. --gt ltfooA xmlnsfoo"http//www.foo.org/"
    gt ltfooBgtabcdlt/fooBgt lt/fooAgt
  • If an XML namespace declaration does not
    contain a prefix, the namespace is the default
    XML namespace and you refer to element type names
    in that namespace without a prefix. For example
  • lt!-- This is equivalent to the previous example
    but uses a default namespace instead of the foo
    prefix. --gt ltA xmlns"http//www.foo.org/"gt
    ltBgtabcdltBgt lt/Agt

33
Next Session Highlights
  • XML (continued)
  • Next Session Reading Assignment
  • Review chapter 2 of Fitzgerald text
  • Skim chapters 6-9 of Fitzgerald text
  • Read chapter 10 of Fitzgerald text
  • Web sites (linked thru the class notes web site)
  • CSS Tutorial (recommended)
Write a Comment
User Comments (0)
About PowerShow.com