XSLT: How Do We Use It? - PowerPoint PPT Presentation

About This Presentation
Title:

XSLT: How Do We Use It?

Description:

XSLT: How Do We Use It? Nancy Hallberg. Nikki Massaro Kauffman. XSLT: Agenda ... XPath is a language for finding ... Nikki Massaro Kauffman, lnm105_at_psu.edu ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 29
Provided by: nikkimassa
Category:
Tags: xslt | nikki | use

less

Transcript and Presenter's Notes

Title: XSLT: How Do We Use It?


1
XSLT How Do We Use It?
  • Nancy Hallberg
  • Nikki Massaro Kauffman

2
XSLT Agenda
  • Introduction Terminology
  • XSLT Walkthrough
  • Client-Side XSLT/XHTML
  • Server-Side XSLT/XHTML
  • More Creative Server-Side XSLT

3
XSLT Terminology
  • CSS
  • HTML v. XHTML
  • XML
  • XPath
  • XSL
  • XSLT

4
XSLT Alphabet Soup
  • CSS HTML
  • XML - Extensible Markup Language
  • XSL - Extensible Stylesheet Language
  • XHTML

5
XSLT XPath
  • XPath is a language for finding information in an
    XML document.
  • XPath is used to navigate through elements and
    attributes in an XML document.
  • Location paths can be Relative or Absolute.

6
XSLT XPath
  • Parents
  • Children
  • Ancestors
  • Descendents
  • Siblings
  • Attributes

7
XSLT XPath
  • Expanded Syntax
  • /childcontacts/childcontact/childlastname
  • Abbreviated Syntax
  • /contacts/contact/lastname

XPath Abbreviated Syntax XPath Abbreviated Syntax XPath Abbreviated Syntax XPath Abbreviated Syntax XPath Abbreviated Syntax XPath Abbreviated Syntax XPath Abbreviated Syntax
/ // . .. _at_
8
XSLT Xpath Examples
  • What do the following indicate?
  • /
  • iddCourseModel/courseTitleShort
  • courseContent/lesson/page
  • ../lesson_at_directory ! lessonshare
  • /contacts//phone

9
XSLT What is XSLT?
  • Extensible Stylesheet Language Transformation
  • Transforms XML documents into other documents
  • Another XML doc
  • HTML doc
  • PDF file
  • And more.

10
XSLT How Do We Use XSLT?
  • Often used as client-side to cache formatting so
    only data is downloaded.
  • Can transform into PDF, EDI, or other formats.
  • We use it for XHTML page navigation, CSS, DWT,
    .htaccess, and more

XSL
XML
Data
XHTML
11
XSLT Template Elements
  • apply-templates
  • call-template
  • choose / when / otherwise
  • comment
  • for-each
  • if
  • import
  • include
  • key
  • output
  • param
  • sort
  • stylesheet
  • template
  • value-of
  • variable

12
XSLT ltxslstylesheetgt
  • Defines the root element of a stylesheet.
  • ltxslstylesheetgt or ltxsltransformgt

13
XSLT ltxsloutputgt
  • Defines the format of the output document.
  • It must be a top-level element.
  • Method attributes are xml, html, text
  • ltxsloutput method"html encoding"ISO-8859-1"/gt

14
XSLT ltxsltemplategt
  • An XSLT stylesheet consists of one or more set of
    rules that are called templates.
  • Each template contains rules to apply when a
    specified node is matched.
  • The value of the match attribute is an XPath
    expression.
  • ltxsltemplate match"/"gt

15
XSLT ltxsltextgt
  • Exactly what it sounds like - writes text to the
    output.
  • Attribute of disable-output-escaping
  • ltxsltext disable-output-escaping"yes"gtlt!CDATAlt
    a name"top" id"top"gtlt/agtgtlt/xsltextgt

16
XSLT ltxslvariablegt
  • Declares a variable
  • The variable is global if it's declared as a
    top-level element, and local if it's declared
    within a template.
  • Once you have set a variable's value, you cannot
    change or modify that value!
  • ltxslvariable name"titleofpage"gtCourse
    Syllabuslt/xslvariablegt

17
XSLT ltxslvalue-ofgt
  • Extracts the value of an XML element and adds it
    to the output stream of the transformation.
  • The value of the select attribute is an XPath
    expression.
  • ltxslvalue-of select"iddCourseModel/CourseTitleLo
    ng /gt

18
XSLT ltxslifgt
  • Yea! Conditionals.
  • Test is a required attribute. It contains the
    expression to be evaluated.
  • ltxslif test"iddCourseModel/gencourPhil"gtlt/xslif
    gt
  • ltxslif test"mi ! ''"gtlt/xslifgt

19
XSLT ltxslfor-eachgt
  • Selects every element in a specified node set.
  • ltxslfor-each select"iddCourseModel/gencourPhil"gt

20
XSLT ltxslsortgt
  • Sorts the output
  • The select attribute indicates what XML element
    to sort on.
  • ltxslsort select"_at_orderNumber"
    data-type"number" order "ascending"/gt

21
XSLT ltxslchoosegt
  • Multiple conditionals
  • Instead of If Then Else or switch case
  • Choose When - Otherwise
  • ltxslchoosegt
  • ltxslwhen test"objectiveStem"gt
  • ltpgtltxslvalue-of select"objectiveStem
    /gtlt/pgt lt/xslwhengt
  • ltxslotherwisegt
  • ltpgtUpon completion of this course you
    willlt/pgt
  • lt/xslotherwisegt
  • lt/xslchoosegt

22
XSLT ltxslapply-templatesgt
  • The ltxslapply-templatesgt element applies a
    template to the current element or to the current
    element's child nodes.
  • Adding a select attribute to the
    ltxslapply-templatesgt element makes it process
    only the child element that matches the value of
    the attribute.
  • Using the select attribute can also specify the
    order in which the child nodes are processed.

23
XSLT ltxslcall-templategt
  • Templates can be called by name.
  • Calls can be recursive.
  • Be careful of the difference between
    apply-templates call-template.

24
XSLT ltxslparamgt
  • Declares a parameter
  • The parameter is global if it's declared as a
    top-level element, and local if it's declared
    within a template.
  • To pass a parameter to it from another template,
    use ltxslwith-paramgt.
  • ltxslparam name"theme"/gt
  • ltxslwith-param name"theme"gtltxslvalue-of
    select"theme"/gtlt/xslwith-paramgt

25
XSLT ltxslimportgt
  • Imports the contents of one style sheet into
    another.
  • An imported style sheet has lower precedence than
    the importing style sheet.
  • This element must appear as the first child node
    of ltxslstylesheetgt or ltxsltransformgt.

26
XSLT ltxslincludegt
  • The ltxslincludegt element is a top-level element
    that includes the contents of one style sheet
    into another.
  • An included stylesheet has the same precedence as
    the including style sheet.
  • This element must appear as a child node of
    ltxslstylesheetgt or ltxsltransformgt.

27
XSLT ltxslkeygt
  • a top-level element which declares a named key
    that can be used in the style sheet with the
    key() function.
  • ltxslkey name"themes" match"theme"
    use"_at_name"/gt
  • ltxslfor-each select"key('themes',
    theme)"gtltxslvariable name"dark"gtltxslvalue-of
    select"_at_dark"/gtlt/xslvariablegtlt/xslfor-eachgt

28
XSLT Help
Feel free to contact us with questions Nancy
Hallberg, ndw1_at_psu.edu Nikki Massaro Kauffman,
lnm105_at_psu.edu Additional resources are
available at http//www.personal.psu.edu/lnm105
Write a Comment
User Comments (0)
About PowerShow.com