WTA4 XSL(2)

download WTA4 XSL(2)

of 32

Transcript of WTA4 XSL(2)

  • 8/10/2019 WTA4 XSL(2)

    1/32

    WTA Topic 4 :

    1

    Extens e Sty es eet

    Language (XSL)

  • 8/10/2019 WTA4 XSL(2)

    2/32

    Topics:XSL

    Learn how XSL can transform XML documents into otherformats such as HTML.XSL stylesheet consists of a set of rules calledtemplates.

    2

    XML result document.Use XPATH expressions in matching patterns to locateparts of an XML document.Sorting and filtering xml data (using XSLT).Creating Conditional Statements.

  • 8/10/2019 WTA4 XSL(2)

    3/32

    IntroductionXSL stands for EXtensible Stylesheet Language,and is a style sheet language for XML documents.XSLT stands for XSL Transformations.How to use XSLT to transform XML documents

    3

    , .CSS = Style Sheets for HTMLXSL = Style Sheets for XML

    XSL can also be used to format data based on itsvalue; ex: to display negative numbers in afinancial report in red.

  • 8/10/2019 WTA4 XSL(2)

    4/32

    XSL consists of three partsXSLTa language for transforming XML documentsinto XHTML.

    4

    a language used by XSLT to locate elementsand/or attributes within an XML documents

    XSL-FO(Formatting Objects) a language for specifyingformatting properties for rendering the XMLdocuments

  • 8/10/2019 WTA4 XSL(2)

    5/32

    XSLXSL can filter and sort XML data using the

    criteria you define, as well as format itsdisplay based on the value of the dataitself.

    5

    When the data is output, you can use XSLto send your XML data to various devices,including handheld devices, print, or voiceoutput.

  • 8/10/2019 WTA4 XSL(2)

    6/32

    XSLT Processing

    reformatted.xslXSLT

    Stylesheet

    6

    mydocument.xml

    (XMLDocument)

    .(Reformatted XML

    Document)XSLT

    Processor

  • 8/10/2019 WTA4 XSL(2)

    7/32

    XSLT Processing XSLT is used to transform XML Documents

    with XSL.

    7

    recognized by the browser, XSLT does thisby converting each XML element into anXHTML element.

    XSLT is a template-based programming

    language.

  • 8/10/2019 WTA4 XSL(2)

    8/32

    XSLT TemplateIt can introduce new XML elements into the outputdocument it creates, or remove others.

    Change the order of elements and choose which to displayand which to hide.

    Create multiple views of the same source document to letyour data be displayed on a broad variety of devices.

    Summary: XSLT lets different kinds of software applicationsexchange XML-enabled data with one another.

    8

  • 8/10/2019 WTA4 XSL(2)

    9/32

    XML Source Tree into XML Result Tree

    LisaDerik

    First NameLast Name

    BillStark

    LisaDerik

    BillStark

    9

  • 8/10/2019 WTA4 XSL(2)

    10/32

    Working For XSLT transformation

    Two documents required XML source documentand an XSLT stylesheet to create a singleresult document.

    XSLT usesXPATH to define parts of the XML source

    document that match one or more predefinedtemplates.

    10

  • 8/10/2019 WTA4 XSL(2)

    11/32

    Details of XSL StylesheetSince an XSL is an XML document, it must begin with an XMLdeclaration:

    Every XSL stylesheet needs to identify the XSL namespace (xslns)so that the parser knows what version of XSLT to use.

    Hence the next statement defines a root element called or .

    or

    11

  • 8/10/2019 WTA4 XSL(2)

    12/32

    Details of XSL StylesheetLater the prefix xsl: is used throughout

    the rest of the XSL stylesheet to identifyall XSL processing statements.

    If theres no xsl: at the beginning of abracketed tag, then that element is simplycopied to the output file without anyprocessing taking place. Thus with this wecan add HTML tags.

    12

  • 8/10/2019 WTA4 XSL(2)

    13/32

    Example : catalog1.xml

    ISBN, PUBLISHER, PAGES?, PRICE)>

    XML in ActionWilliam J.

    Pardi

    0-07-914702-9Microsoft Press492470.00

    13

    ]>

    Oracle 8iRichard

    Gosling0-07-913702-4BPB Publications393410.00

    XML to codeJesse Liberty1-861000-95-2Wrox Press393560.00Java UnleashedJames

    Spencer0-7456-0964-1Techmedia

    Publications491670.00

  • 8/10/2019 WTA4 XSL(2)

    14/32

    Example 1 : xslcatalogs1.xsl

    Catalogs Book InformationBOOK NAMEAUTHOR NAME

    14

    PUBLISHERPAGESPRICE

  • 8/10/2019 WTA4 XSL(2)

    15/32

    XSL uses TemplatesThe Element

    The element is used to build templates.The match attribute indicates where to look for a matchbetween the XML and XSL documents.The value of the match attribute is an XPath expression

    15

    (i.e. match="/" defines the whole document).

    XSLT Element

    Is used to extract the value of a selected node.

  • 8/10/2019 WTA4 XSL(2)

    16/32

    Filtering XSLT Element

    The element allows you to do looping inXSLT

    Filtering the OutputWe can also filter the out ut from the XML file b addin a

    16

    criterion to the select attribute in the element.

  • 8/10/2019 WTA4 XSL(2)

    17/32

    Sorting XSLT Element

    The element is used to sort theoutput.Ex : to sort the catalog as per book name in

    17

  • 8/10/2019 WTA4 XSL(2)

    18/32

    Example 2 : xslcatalogs2.xsl

    Catalogs Book InformationBOOK NAMEAUTHOR NAME

    18

    PUBLISHERPAGESPRICE

  • 8/10/2019 WTA4 XSL(2)

    19/32

    Conditional StatementThe element

    Is used to put a conditional test attribute,against the content of the XML file.Ex: to display books only with price less than

    rupees. .

    19

  • 8/10/2019 WTA4 XSL(2)

    20/32

    Example 3 : xslcatalogs3.xsl

    Catalogs Book InformationBOOK NAMEAUTHOR NAME

    20

    PUBLISHERPAGESPRICE

  • 8/10/2019 WTA4 XSL(2)

    21/32

    Multiple ChoicesThe element

    Is used in conjunction with and to express multiple conditional tests.

    Syntax

    21

    ... some output ...

    ... some output ....

  • 8/10/2019 WTA4 XSL(2)

    22/32

    Example 4.1 of choose(xml file)

    Empire BurlesqueBob DylanUSA

    Columbia10.901985

    Still got the bluesGary Moore

    22

    HM records10.201990

    ErosEros RamazzottiEUBMG9.901997

    Unchain my heartJoe CockerUSAEMI8.201987

    If we want to display the cd details from the

  • 8/10/2019 WTA4 XSL(2)

    23/32

    Example 4.1 of choose(xsl file)

    My CD Collection

    TitleArtist

    < tr>

    XML file in a table and highlight the artistwhere cd price is > 10 in a different color.

    23

    xchoose.xml

    If we want to present the contents of our XML

  • 8/10/2019 WTA4 XSL(2)

    24/32

    Example 4.2 of choose(xml file)

  • 8/10/2019 WTA4 XSL(2)

    25/32

    Example 4.2 of choose(xml file)

    25

    Foo Item< t >

    Carbs (g)Fiber (g)Fat (g)Energy (kj)

    < t >

    food.xml

  • 8/10/2019 WTA4 XSL(2)

    26/32

    Applying TemplatesThe select attribute that appears in elementprocesses only the child element that matches the value shown.

    ,

    element would be selected.

    If value has to be set only to certain child elements then separatewith pipe character.

    26

  • 8/10/2019 WTA4 XSL(2)

    27/32

    Example 5 : xsltemplate.xml

    678

    782

    HarshMehta

    BTech12IT

    27

    SmitaLondhe

    MBATech12Computer

  • 8/10/2019 WTA4 XSL(2)

    28/32

    Example 5 : xsltemplate.xsl

    28xsltemplate.xml

  • 8/10/2019 WTA4 XSL(2)

    29/32

    Example 6 : xslplanes.xml

    1977 Cessna

    29

    Light blue and white

    1975 Piper

    Apache White

  • 8/10/2019 WTA4 XSL(2)

    30/32

    Example 6 : xslplanes.xsl

    Airplane Descriptions

    - " "

    30

    Year:
    Make:
    Model:

    Color:

    xslplanes.xml

  • 8/10/2019 WTA4 XSL(2)

    31/32

    XPathXPath is used to navigate through

    elements and attributes in an XMLdocument.

    31

    XPath is a major element in the W3C'sXSL standard. An understanding of XPathis fundamental for advanced use of XML.

    Without any XPath knowledge, you will not

    be able to create XSLT documents.

  • 8/10/2019 WTA4 XSL(2)

    32/32

    XSL-FOXSL-FO describes the formatting of XML

    data for output to screen, paper or othermedia.

    32

    XSL-FO documents are XML files withinformation about the output layout andoutput content.