XSLT - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

XSLT

Description:

TITLE Empire Burlesque /TITLE ARTIST Bob Dylan /ARTIST COUNTRY USA /COUNTRY ... Empire Burlesque Bob Dylan. 12 ?xml version='1.0' ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 38
Provided by: sanjay70
Learn more at: https://web.mst.edu
Category:
Tags: xslt | empire | pattern

less

Transcript and Presenter's Notes

Title: XSLT


1
XSLT XML stylesheet Transformation
2
An XSLT stylesheet is an XML document defining
a transformation for a class of XML documentsA
stylesheet seperates contents and logical
structure from presentation

3
XSLT
  • xslstylesheet
  • A stylesheet is represented by an xslstylesheet
    element in an XML document.
  • xsltransform is allowed as a synonym for
    xslstylesheet.
  • The namespace http//www.w3.org/1999/XSL/Transform
    is used to recognize the XSL elements

4
  • A template rule is specified with the
    xsltemplate element.
  • The content of the xsltemplate element is the
    template
  • The match attribute is a Pattern that identifies
    the source node or nodes to which the rule
    applies.

5
  • select
  • A select attribute can be used to process nodes
    selected by an expression.
  • The value of the select attribute is an
    expression.
  • The xslvalue-of element is instantiated to
    create a text node in the result tree.

6
  • xsltext
  • ltxsltext ...gt ... lt/...gt
  • as raw text but allows control of white-space
    stripping and escaping
  • ltxslcommentgt ... lt/...gt
  • creates comment

7
  • The xslfor-each instruction contains a template,
    which is instantiated for each node selected by
    the expression specified by the select attribute.
    The select attribute is required
  • ltxslfor-each select"node-set expression"gt
    template lt/...gt
  • instantiate template for each node in node-set
  • ltxslapply-templates select"node-set expression"
    .../gt
  • apply pattern matching and template instantiation
    on selected nodes (default all children)

8
  • lt?xml version"1.0"?gt
  • ltCATALOGgt
  • ltCDgt
  • ltTITLEgtEmpire Burlesquelt/TITLEgt ltARTISTgtBob
    Dylanlt/ARTISTgt ltCOUNTRYgtUSAlt/COUNTRYgt
    ltCOMPANYgtColumbialt/COMPANYgt ltPRICEgt10.90lt/PRICEgt
    ltYEARgt1985lt/YEARgt
  • lt/CDgt
  • lt/CATALOGgt

9
  • lt?xml version"1.0" ?gt
  • ltxslstylesheet xmlnsxsl"http//www.w3.org/TR/WD
    -xsl"gt
  • ltxsltemplate match"/"gt lthtmlgt ltbodygt
  • lttable border"1"gt lttrgt  ltthgtTitlelt/thgt  
    ltthgtArtistlt/thgt   lt/trgt lttrgt  lttdgt.lt/tdgt  
    lttdgt.lt/tdgt  
  • lt/trgt 
  • lt/tablegt 
  • lt/bodygt 
  • lt/htmlgt 
  • lt/xsltemplategt 
  • lt/xslstylesheetgt

Title Artist . .
10
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltbodygt lttable border"1"gt
  • lttrgt ltthgtTitlelt/thgt
  • ltthgtArtistlt/thgt lt/trgt
  • lttrgt
  • lttdgtltxslvalue-of select"CATALOG/CD/TITLE"/gtlt/tdgt
    lttdgtltxslvalue-of select "CATALOG/CD/ARTIST"/gtlt/
    tdgt
  • lt/trgt lt/tablegt lt/bodygt lt/htmlgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

11
  • Title Artist
  • Empire Burlesque Bob Dylan

12
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltbodygt lttable border"1"gt
  • lttrgt ltthgtTitlelt/thgt ltthgtArtistlt/thgt lt/trgt
    ltxslfor-each select"CATALOG/CD"gt lttrgt
    lttdgtltxslvalue-of select"TITLE"/gtlt/tdgt
  • lttdgtltxslvalue-of select"ARTIST"/gtlt/tdgt lt/trgt
    lt/xslfor-eachgt lt/tablegt lt/bodygt lt/htmlgt
    lt/xsltemplategt
  • lt/xslstylesheetgt
  • It will construct complete table

13
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt
  • ltbodygt lttable border"2" bgcolor"yellow"gt lttrgt
  • ltthgtTitlelt/thgt ltthgtArtistlt/thgt
  • lt/trgt
  • ltxslfor-each select"CATALOG/CD"gt lttrgt
    lttdgtltxslvalue-of select"TITLE"/gtlt/tdgt
    lttdgtltxslvalue-of select"ARTIST"/gtlt/tdgt
  • lt/trgt lt/xslfor-eachgt lt/tablegt lt/bodygt
  • lt/htmlgt lt/xsltemplategt
  • lt/xslstylesheetgt

14
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltbodygt lttable border"2" bgcolor"yellow"gt
  • lttrgt ltthgtTitlelt/thgt ltthgtArtistlt/thgt lt/trgt
    ltxslfor-each select"CATALOG/CD" order-by"
    ARTIST"gt
  • lttrgt lttdgtltxslvalue-of select"TITLE"/gtlt/tdgt
    lttdgtltxslvalue-of select"ARTIST"/gtlt/tdgt lt/trgt
    lt/xslfor-eachgt lt/tablegt
  • lt/bodygt
  • lt/htmlgt lt/xsltemplategt
  • lt/xslstylesheetgt

15
  • ltxslTutorial gt
  • lttitlegtXSLlt/titlegt
  • ltauthorgtJohn Smithlt/authorgt
  • lt/xslTutorialgt
  • ltxslstylesheet version'1.0' xmlnsxsl'http//ww
    w.w3.org/1999/XSL/Transform' gt
  • ltxsltemplate match"/"gt
  • ltH1gtltxslvalue-of select"//title"/gtlt/H1gt
  • ltH2gtltxslvalue-of select"//author"/gtlt/H2gt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

16
  • ltHTMLgt
  • ltHEADgt lt/HEADgt
  • ltBODYgt
  • ltH1gtXSLlt/H1gt
  • ltH2gtJohn Smithlt/H2gt
  • lt/BODYgt
  • lt/HTMLgt

17
  • XSL
  • John Smith

18
  • xslstylesheet version'1.0' xmlnsxsl'http//www
    .w3.org/1999/XSL/Transform' gt
  • ltxsltemplate match"/"gt
  • ltH2gtltxslvalue-of select"//author"/gtlt/H2gt
  • ltH1gtltxslvalue-of select"//title"/gtlt/H1gt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

19
  • HTMLgt
  • ltHEADgt lt/HEADgt
  • ltBODYgt
  • ltH2gtJohn Smithlt/H2gt
  • ltH1gtXSLlt/H1gt
  • lt/BODYgt
  • lt/HTMLgt

20
  • John Smith
  • XSL

21
  • ltxslTutorial gt
  • ltdog name'Joe'gt
  • ltdata weight'18 kg' color"black"/gt
  • lt/doggt
  • lt/xslTutorial

22
  • data/_at_color
  • matches color attribute of data element which is
    a child of dog element

23
  • ltxslstylesheet version'1.0' xmlnsxsl'http//ww
    w.w3.org/1999/XSL/Transform' gt
  • ltxsltemplate match"dog"gt
  • ltPgtltBgtltxsltextgt Dog lt/xsltextgt lt/Bgt
  • ltxslvalue-of select"_at_name"/gtlt/Pgt
  • ltPgtltBgtltxsltextgt Color lt/xsltextgt lt/Bgt
  • ltxslvalue-of select"data/_at_color"/gtlt/Pgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

24
  • ltHTMLgt
  • ltHEADgt lt/HEADgt
  • ltBODYgt
  • ltPgt
  • ltBgtDog lt/BgtJoelt/Pgt
  • ltPgt
  • ltBgtColor lt/Bgtblacklt/Pgt lt/BODYgt lt/HTMLgt

25
  • Dog Joe
  • Color black

26
  • ltxslTutorial gt
  • ltnamegtJohnlt/namegt
  • ltnamegtJosualt/namegt
  • ltnamegtCharleslt/namegt
  • ltnamegtAlicelt/namegt
  • ltnamegtMarthalt/namegt
  • ltnamegtGeorgelt/namegt
  • lt/xslTutorialgt

27
  • ltxslstylesheet version'1.0' xmlnsxsl'http//ww
    w.w3.org/1999/XSL/Transform' gt
  • ltxsltemplate match"/"gt
  • ltTABLEgt
  • ltxslfor-each select"//name"gt
  • ltxslsort order"ascending" select"."/gt
  • ltTRgtltTHgt
  • ltxslvalue-of select"."/gtlt/THgtlt/TRgt
  • lt/xslfor-eachgt
  • lt/TABLEgt
  • lt/xsltemplategt
  • lt/xslstylesheet

28
  • HTMLgt
  • ltHEADgt lt/HEADgt
  • ltBODYgt
  • ltTABLEgt
  • ltTRgt
  • ltTHgtAlicelt/THgtlt/TRgt
  • ltTRgt
  • ltTHgtGeorgelt/THgtlt/TRgt
  • ltTRgt
  • ltTHgtCharleslt/THgtlt/TRgt
  • ltTRgt
  • ltTHgtJohnlt/THgtlt/TRgt
  • ltTRgt
  • ltTHgtJosualt/THgtlt/TRgt
  • ltTRgt
  • ltTHgtMarthalt/THgtlt/TRgtlt/TABLEgt lt/BODYgt lt/HTMLgt

29
  • Sorting is specified by adding xslsort elements
    as children of xslapply-templates or
    xslfor-each. The first xslsort child specifies
    the primary sort key, the second xslsort child
    specifies the secondary sort key and so on.
  • When used in xslfor-each, xslsort elements must
    occur first.

30
  • order specifies whether the strings should be
    sorted in ascending or descending order
    ascending specifies ascending order descending
    specifies descending order the default is
    ascending

31
  • xslstylesheet version'1.0' xmlnsxsl'http//www
    .w3.org/1999/XSL/Transform' gt
  • ltxsltemplate match"/"gt
  • ltTABLEgt
  • ltxslfor-each select"//name"gt
  • ltxslsort order"descending" select"."/gt
  • ltTRgtltTHgtltxslvalue-of select"."/gtlt/THgtlt/TRgt
  • lt/xslfor-eachgt
  • lt/TABLEgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

32
  • Martha
  • Josua
  • John
  • Charles
  • George
  • Alice

33
  • ltxslstylesheet version'1.0' xmlnsxsl'http//ww
    w.w3.org/1999/XSL/Transform' gt
  • ltxsltemplate match"/"gt
  • ltTABLEgt
  • ltxslapply-templates select"//name"gt
  • ltxslsort order"descending" select"."/gt
  • lt/xslapply-templatesgt
  • lt/TABLEgt
  • lt/xsltemplategt
  • ltxsltemplate match"name"gt
  • ltTRgtltTHgtltxslvalue-of select"."/gtlt/THgtlt/TRgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

34
  • Martha
  • Josua
  • John
  • Charles
  • George
  • Alice

35
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
    ltxsltemplate match"/"gt
  • lthtmlgt ltbodygt lttable border"2" bgcolor"yellow"gt
    lttrgt ltthgtTitlelt/thgt ltthgtArtistlt/thgt lt/trgt
  • ltxslfor-each select"CATALOG/CDARTIST'Bob
    Dylan'"gt lttrgt lttdgtltxslvalue-of
    select"TITLE"/gtlt/tdgt lttdgtltxslvalue-of
    select"ARTIST"/gtlt/tdgt lt/trgt lt/xslfor-eachgt
  • lt/tablegt lt/bodygt
  • lt/htmlgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

36
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
    ltxsltemplate match"/"gt
  • lthtmlgt ltbodygt lttable border"2" bgcolor"yellow"gt
  • lttrgt ltthgtTitlelt/thgt ltthgtArtistlt/thgt lt/trgt
    ltxslfor-each select"CATALOG/CD"gt
  • ltxslif match".ARTIST'Bob Dylan'"gt
  • lttrgt lttdgtltxslvalue-of select"TITLE"/gtlt/tdgt
    lttdgtltxslvalue-of select"ARTIST"/gtlt/tdgt lt/trgt
    lt/xslifgt lt/xslfor-eachgt lt/tablegt lt/bodygt
    lt/htmlgt
  • lt/xsltemplategt
  • lt/xslstylesheetgt

37
  • lt?xml version'1.0'?gt ltxslstylesheet
    xmlnsxsl"http//www.w3.org/TR/WD-xsl"gt
    ltxsltemplate match"/"gt
  • lthtmlgt ltbodygt
  • lttable border"2" bgcolor"yellow"gt lttrgt
    ltthgtTitlelt/thgt ltthgtArtistlt/thgt lt/trgt
  • ltxslfor-each select"CATALOG/CD"gt lttrgt
    lttdgtltxslvalue-of select"TITLE"/gtlt/tdgt
    ltxslchoosegt
  • ltxslwhen match".ARTIST'Bob Dylan'"gt lttd
    bgcolor"ff0000"gt ltxslvalue-of
    select"ARTIST"/gt lt/tdgt lt/xslwhengt
    ltxslotherwisegt lttdgtltxslvalue-of
    select"ARTIST"/gtlt/tdgt lt/xslotherwisegt
    lt/xslchoosegt lt/trgt lt/xslfor-eachgt..
Write a Comment
User Comments (0)
About PowerShow.com