Announcement - PowerPoint PPT Presentation

About This Presentation
Title:

Announcement

Description:

Lecture 16 the xsl:variable element The format of the xsl:variable element is or – PowerPoint PPT presentation

Number of Views:5
Avg rating:3.0/5.0
Slides: 7
Provided by: JimBo156
Category:

less

Transcript and Presenter's Notes

Title: Announcement


1
Lecture 16
2
the xslvariable element
  • The format of the xslvariable element is
  • ltxslvariable nameqname selectexpression/gt
  • or
  • ltxslvariable nameqnamegt
  • lt!-- Content template --gt
  • lt/xslvariablegt
  • or
  • ltxslvariable nameqname/gt
  • It tells the XSLT processor to
  • instantiate the variable with the given name to
    the value of the expression or to the value of
    the template or to the empty string
  • Later, the value of the variable can be accessed
    by an expression comprising followed by the
    name
  • xslvariables are not mutable

3
Example usage of the xslvariable element
  • lt?xml version"1.0"?gt
  • ltxsltransform version"1.0" xmlnsxsl"http//www
    .w3.org/1999/XSL/Transform"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltheadgtlttitlegtSecond-hand
    bookslt/titlegtlt/headgt ltbodygt lttable rules"all"gt
  • lttheadgtlttrgtltthgtPricelt/thgtltthgtISBNlt/thgtltthgtTitlelt/
    thgtlt/trgtlt/theadgt lttbodygt
  • ltxslfor-each select"./stock/secondHandBooks/boo
    k"gt
  • ltxslvariable name"thisISBN
    select"./_at_isbn"/gt
  • lttrgtlttdgtltxslvalue-of select"price"/gtlt/tdgt
  • lttdgt ltxslvalue-of select"thisISBN"/gt
    lt/tdgtlttdgt
  • ltxslvalue-of select"/stock/publications/book_at_is
    bnthisISBN/title"/gtlt/tdgtlt/trgt
  • lt/xslfor-eachgt
  • lt/tbodygt lt/tablegtlt/bodygtlt/htmlgt lt/xsltemplategt
    lt/xsltransformgt

4
The scope of an xslvariable element
  • lt?xml version"1.0"?gt
  • ltxsltransform version"1.0" xmlnsxsl"http//www
    .w3.org/1999/XSL/Transform"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltheadgtlttitlegtSecond-hand
    bookslt/titlegtlt/headgt ltbodygt lttable rules"all"gt
  • lttheadgtlttrgtltthgtPricelt/thgtltthgtISBNlt/thgtltthgtTitlelt/
    thgtlt/trgtlt/theadgt lttbodygt
  • ltxslfor-each select"./stock/secondHandBooks/boo
    k"gt
  • lttrgt lttdgtltxslvariable name"thisISBN
    select"./_at_isbn"/gt
  • ltxslvalue-of select"price"/gtlt/tdgt
  • lttdgt ltxslvalue-of selectthisISBN "/gt
    lt/tdgtlttdgt
  • ltxslvalue-of select"/stock/publications/book_at_is
    bnthisISBN/title"/gtlt/tdgtlt/trgt
  • lt/xslfor-eachgtlt/tbodygt lt/tablegtlt/bodygtlt/htmlgt
    lt/xsltemplategt lt/xsltransformgt
  • Scope of an xslvariable is the element within
    which it was declared

5
Another cross-referencing example
  • The type of an item refers to the id of a car
    model
  • To produce the HTML table, we use an xslvariable
    to remember an items type and search for model
    containing this id in the set of models

6
The XSL stylesheet for previous slide
  • lt?xml version"1.0"?gt
  • ltxsltransform version"1.0" xmlnsxsl"http//www
    .w3.org/1999/XSL/Transform"gt
  • ltxsltemplate match"/"gt
  • lthtmlgt ltheadgtlttitlegtSecond-hand
    carslt/titlegtlt/headgt ltbodygt lttable rules"all"gt
  • lttheadgtlttrgtltthgtItemlt/thgtltthgtModellt/thgtltthgtEngine
    Sizelt/thgtltthgtPricelt/thgtlt/trgtlt/
  • theadgt lttbodygt
  • ltxslfor-each select"./stock/cars/item"gt
  • ltxslvariable name"thisType" select"./type"/gt
  • lttrgt
  • lttdgt ltxslvalue-of select"./_at_num"/gt lt/tdgt
  • lttdgt ltxslvalue-of select"/stock/models/model_at_id
    thisType/name"/gt lt/tdgt
  • lttdgt ltxslvalue-of select"/stock/models/model_at_id
    thisType/engineSize"/gt lt/tdgt
  • lttdgt ltxslvalue-of select"./price"/gt lt/tdgt
  • lt/trgt
  • lt/xslfor-eachgt
  • lt/tbodygt lt/tablegtlt/bodygtlt/htmlgt
  • lt/xsltemplategt
  • lt/xsltransformgt
Write a Comment
User Comments (0)
About PowerShow.com