SlideShare a Scribd company logo
1 of 45
Displaying Data with XSLT


Objectives
In this lesson, you will learn to:
 Perform conditional formatting in a style sheet
 Use XPath pattern matching in a style sheet
 Create a comma-separated list of values
 Import a style sheet in another style sheet




©NIIT                    eXtensible Markup Language/Lesson 6/Slide 1 of 45
Displaying Data with XSLT

Problem Statement 6.D.1
A list of products sold at CyberShoppe needs to be displayed.
These products need to be categorized based on their prices.
The details about products priced higher than $50 are to be
displayed in red and the rest are to be displayed in green.
The details to be displayed include the product name,
description, price, and quantity on hand.




   ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 2 of 45
Displaying Data with XSLT

Task List
 Identify data to be displayed.
 Identify the elements required to format data based on
  a condition.
 Create a style sheet to format data based on a
  condition.
 Apply the style sheet to the XML document.
 View the XML document.




 ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 3 of 45
Displaying Data with XSLT

Task 1: Identify data to be displayed.
Result
 As per the scenario, the data that has to be displayed is as
  follows:
    PRODUCTNAME
    DESCRIPTION
    PRICE
    QUANTITY




   ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 4 of 45
Displaying Data with XSLT

Task 2: Identify the elements required to format data
based on a condition.

The if Element
 The if element provides a simple if-then construct. The
  syntax of if element is as follows:

  xsl:if test=“condition”
  [actions to be performed if the condition
  is true]
  /xsl:if




  ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 5 of 45
Displaying Data with XSLT

Task 2: Identify the elements …a condition. (Contd.)
The choose Element
 The choose element is used to make a choice when there
  are two or more possible courses of action.
 It provides a means for testing multiple conditions.




   ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 6 of 45
Displaying Data with XSLT

Task 2: Identify the elements …a condition.
(Contd.)
 The syntax of the choose element is as follows:
  xsl:choose
  xsl:when test=condition
  [action to be taken]
  /xsl:when
  :
  :
  xsl:otherwise
  [action to be taken]
  /xsl:otherwise
  /xsl:choose
  ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 7 of 45
Displaying Data with XSLT

Task 2: Identify the elements …a condition. (Contd.)
 The following table lists the comparison and boolean
  operators that can be used with the xsl:choose and xsl:if
  elements:
     Operator               Meaning                                  Example
 =              Equal to                         PRICE[. = 20]
                                                 PRODUCTNAME[. = ‘Mini Bus’]
 !=             Not equal to                     PRICE[. != 20]
                                                 PRODUCTNAME[. != ‘Barbie Doll’]
 lt;           Less than                        PRICE[. lt; 20]

 gt;           Greater than                     PRICE[. gt; 20]

 lt;=          Less than or equal to            PRICE[. lt;= 20]

 gt;=          Greater than or equal to         PRICE[. gt;= 20]




     ©NIIT                              eXtensible Markup Language/Lesson 6/Slide 8 of 45
Displaying Data with XSLT

Task 2: Identify the elements … a condition. (Contd.)


 Operator        Meaning                                          Example
and           Logical AND         PRICE[. gt 20 and . lt; 30]

or            Logical OR          PRICE[. = 20 or . = 45]

not           Negation operator   PRICE[not(. = 30)]



The operators given in bold in the above list are Microsoft extensions to the
original list of operators recommended by W3C.




      ©NIIT                          eXtensible Markup Language/Lesson 6/Slide 9 of 45
Displaying Data with XSLT

Task 2: Identify the elements … a condition.
(Contd.)
Result
 As the value of the PRICE element needs to be checked
  for a range of values, the choose element in combination
  with when and otherwise can be used for performing
  the check.




  ©NIIT                eXtensible Markup Language/Lesson 6/Slide 10 of 45
Displaying Data with XSLT

Task 3: Create a style sheet to format data based
on a condition.


Task 4: Apply the style sheet to the XML document.


Task 5: View the XML document.




  ©NIIT             eXtensible Markup Language/Lesson 6/Slide 11 of 45
Displaying Data with XSLT

Just a Minute…
 The details about the books sold at CyberShoppe need to
 be displayed. Books priced higher than $100 are to be
 displayed in red, those priced higher than $75 are to be
 displayed in blue, and the rest are to be displayed in
 green.




 ©NIIT                eXtensible Markup Language/Lesson 6/Slide 12 of 45
Displaying Data with XSLT

Problem Statement 6.D.2
 CyberShoppe needs to display a summarized report about
 orders. The data about the products and all orders placed
 for products is stored in an XML document. This data
 includes the details about a product, such as product ID,
 product name, and price per unit. For each product, the data
 about all orders placed against that product is also stored.
 This data includes the order number, shipping address, and
 the order quantity.




  ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 13 of 45
Displaying Data with XSLT

Problem Statement 6.D.2 (Contd.)
The structure of the XML document is given below:

           SUMMARY

            PRODUCT

                    ORDER

                   SHIPPING
                   ADDRESS
                  QUANTITY


   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 14 of 45
Displaying Data with XSLT

Task List
 Identify the data to be displayed.
 Identify a mechanism to display summarized data.
 Identify the XPath expressions required for performing
  calculations.
 Identify the functions required for performing
  calculations.
 Create an XSLT style sheet containing XPath patterns
  and functions.
 Create the XML document.
 View the XML document.



 ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 15 of 45
Displaying Data with XSLT

Task 1: Identify the data to be displayed.
Result
 As per the given scenario, the details to be displayed are
  as follows:
    Product ID
    Product Name
    Price per unit
    Details about orders placed against the product:
         ® Order   number
         ® Shipping   address
         ® Total   quantity
         ® Order   value
    Total sales amount for the product
   ©NIIT                      eXtensible Markup Language/Lesson 6/Slide 16 of 45
Displaying Data with XSLT

Task 2: Identify a mechanism to display summarized
data.
 XML Path (XPath) language is used for searching and
  retrieving information from an XML file.
 XPath treats an XML document as a tree of interrelated
 branches and nodes.
 A node can be of any type, such as an element, attribute,
  processing instruction (PI), comment, text, or namespace.
 XPath provides a set of expressions and functions that can
  be used for matching nodes in an XML document. As a
  result of matching nodes with a specific pattern, a set of
  nodes referred to as node set is retrieved.


   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 17 of 45
Displaying Data with XSLT

Task 2: Identify a … summarized data. (Contd.)
Result
 As XPath provides a set of expressions and functions that
  can match specific patterns, retrieve results, and perform
  additional operations such as calculations, XPath can be
  used along with XSLT for displaying data in the given
  scenario.




   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 18 of 45
Displaying Data with XSLT
Task 3: Identify the XPath expressions required for
performing calculations.
 XPath expressions can be used to retrieve data based on
  specific conditions. You can apply constraints by adding a
  filter clause, which is otherwise referred to as a filter
  pattern.
 Using XPath, you can create expressions that can identify
  the nodes in an XML document based on names and
  values. You can also create expressions that identify the
  relationship of a node with other nodes in the document.
  These expressions can be used with XSLT patterns for
  matching and retrieving nodes.
 XPath expressions work on the basis of a specific context.
 XPath expressions can be created using a set of operators
  and special characters. The following table describes these
  operators:
   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 19 of 45
Displaying Data with XSLT

    Task 3: Identify the … performing calculations.
    (Contd.)
     Operator/        Example                               Description
      Special
    Character
/                /PRODUCTDATA        Selects immediate child elements of PRODUCTDATA. If this
                                     operator occurs at the start of the pattern, it indicates that the
                                     child elements should be selected from the root node.

//               //PRODUCTNAME       Searches for the specified element at any node level.


.                .PRODUCTNAME        Indicates the current context.


*                *                   Selects all elements regardless of the element name.


@                @PRODUCTID          Used as a prefix for the attribute PRODUCTID.




       ©NIIT                     eXtensible Markup Language/Lesson 6/Slide 20 of 45
Displaying Data with XSLT

Task 3: Identify the … performing calculations.
(Contd.)
     Operator/        Example                                   Description
      Special
     Character
@*               @*                      Selects all attributes, regardless of the name.

:                :                       Separates the namespace prefix from the element or
                                         attribute name.

()               (PRICE*QUANTITY)        Used to group operations.


[]               [@PRODUCTID='P001']     Applies a filter pattern.



+                num1 + num2             Adds two numbers, returning their sum.


-                num1 - num2             Subtracts num2 from num1, returning the difference.




      ©NIIT                         eXtensible Markup Language/Lesson 6/Slide 21 of 45
Displaying Data with XSLT

Task 3: Identify the …performing calculations.
(Contd.)

      Operator/         Example                              Description
       Special
     Character
*                 num1 * num2           Multiplies num1 by num2, returning the product.


div               num1 div num2         Divides num1 by num2, returning the quotient.

mod               num1 mod num2         Returns the modulus—that is, divides num1 by num2 and
                                        returns the remainder.
..                ../PRODUCTNAME        Selects the PRODUCTNAME element, which exists within
                                        the parent of the current element.




       ©NIIT                       eXtensible Markup Language/Lesson 6/Slide 22 of 45
Displaying Data with XSLT

Task 3: Identify the … performing calculations.
  (Contd.)
Result
 In the given scenario, an XPath expression can be created
  for calculating the order value:
   xsl:value-of select='(../@PRICE) *
  (QUANTITY)'/
 The above expression instructs the XSLT processor to pick
  up the value of the PRICE attribute of the parent element
  and multiply it by the value of the QUANTITY element.




   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 23 of 45
Displaying Data with XSLT

Task 4: Identify the functions required for performing
calculations.
XPath functions
 XPath provides a various categories of functions. They are:
    string
    node set
    boolean
    number
 These functions can take one or more arguments.




   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 24 of 45
Displaying Data with XSLT

Task 4: Identify the ... performing calculations.
(Contd.)
String functions
 The string functions of XPath are used to perform string
  operations, such as finding the length of a string or
  converting a string from uppercase to lowercase.
 Some of the string functions provided in XPath are:
    string(obj?): Converts the argument to a string value.
    starts-with(str, str): Returns true if the first string begins
     with the second string
    contains(str, str): Returns true if the first string contains
     the second string.

   ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 25 of 45
Displaying Data with XSLT

Task 4: Identify the … performing calculations.
(Contd.)
String functions (Contd.)
    substring(str, num, num?): Returns a portion of the
     string starting from the position specified in the second
     argument. Returns the number of characters specified in
     the third argument.
    substring-before(str, str): Returns the portion of the first
     string that precedes the second string.
    substring-after(str, str): Returns the portion of the first
     string that follows the second string.
    string-length(str?): Returns the length of the string.


   ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 26 of 45
Displaying Data with XSLT

Task 4: Identify the … performing calculations.
(Contd.)
Node-Set functions
 Node-set functions are used to manipulate node sets or to
  return information about node sets.
 Some of the node-set functions provided in XPath are:
    last(): Returns the number of the last node in the current
     node-set.
    position(): Returns the position of the current node
     within the parent node.
    count(ns): Returns the number of occurrences of the
     specified node-set.
    id(obj): Returns the element with the specified unique
     ID.

   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 27 of 45
Displaying Data with XSLT

Task 4: Identify the … performing calculations.
(Contd.)
Boolean functions
 All boolean functions return either true or false.
 Some of the node-set functions provided in XPath are:
     boolean(obj?): Converts the argument to a boolean.
     not(boolean): Takes an expression, which returns a
      boolean value, as its argument. Negates the result of
      the Boolean expression.




  ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 28 of 45
Displaying Data with XSLT

Task 4: Identify the … performing calculations.
(Contd.)
Numeric functions
 XPath provides numeric functions for various purposes,
  such as adding numbers, finding the nearest integer value,
  and converting strings to numbers.
 Some of the numeric function provided in XPath are:
    number(obj?): Converts the argument to a number.
    sum(ns): Sums up the values of the nodes contained in
     the node-set, which is passed as an argument to the
     function.
    floor(num): Returns the largest integer that is less than
     or equal to the argument.
    ceiling(num): Returns the smallest integer that is greater
     than or equal to the argument.
   ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 29 of 45
Displaying Data with XSLT
Task 4: Identify the … performing calculations.
(Contd.)
    round(num): Rounds up the number to the nearest
     integer.
Result
 As per the scenario, the sum() function of XPath needs to
  be used for calculating the product sales value of each
  product. The code for calculating the product sales values
  is given as follows:
  xsl:value-of select='(../@PRICE) * (QUANTITY)'/
  
  xsl:value-of select='(./@PRICE) *
  sum(./ORDER/QUANTITY)'/


   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 30 of 45
Displaying Data with XSLT
Task 5: Create an XSLT style sheet containing XPath
patterns and functions.


Task 6: Create the XML document.


Task 7: View the XML document.




  ©NIIT             eXtensible Markup Language/Lesson 6/Slide 31 of 45
Displaying Data with XSLT

Problem Statement 6.D.3
 The details about the books that are available for sale at
 CyberShoppe are stored in an XML document. The book
 details, such as book ID, title, rate, author first name, and
 author last name should be displayed in a tabular format.
 The first name and last name of an author should be
 displayed in a single column, AUTHOR(S). If a book has
 multiple authors, their names should be displayed as
 comma-separated values.




  ©NIIT                   eXtensible Markup Language/Lesson 6/Slide 32 of 45
Displaying Data with XSLT

Task List
 Identify the data to be displayed.
 Identify a mechanism to be used to display the data in
  a tabular format.
 Identify the elements required to display data in a
  tabular format.
 Identify a mechanism to create a comma-separated
  list of values.
 Create a style sheet.
 Apply the style sheet to the XML document.
 View the XML document.


©NIIT                 eXtensible Markup Language/Lesson 6/Slide 33 of 45
Displaying Data with XSLT

Task 1: Identify the data to be displayed.
Result
In the given scenario, the data to be displayed is as
   follows:
 BOOKID
 TITLE
 RATE
 AUTHOR
     FIRSTNAME
     LASTNAME


  ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 34 of 45
Displaying Data with XSLT

Task 2: Identify a mechanism to be used to display
the data in a tabular format.
 Information pertaining to the way in which XML data must
  appear in a browser is specified in either CSS or XSLT
  style sheets.
 However, in certain situations, these two methods do not
  have the capability to display data in certain formats.
 You can combine the features of HTML and XSLT to format
  the data from an XML document as per requirements.




 ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 35 of 45
Displaying Data with XSLT

Task 2: Identify a mechanism …the data in a tabular
format. (Contd.)
Result:
 In the given scenario, HTML tags can be used in an XSLT
  to display data in a tabular format.




  ©NIIT                eXtensible Markup Language/Lesson 6/Slide 36 of 45
Displaying Data with XSLT

Task 3: Identify the elements required to display data
in a tabular format.
Using HTML Elements in an XSLT Style Sheet
 In order to use HTML tags in an XSLT style sheet, you
  must write the HTML code to display the data in the desired
  format.
 This code is then embedded in the XSLT document.




 ©NIIT                 eXtensible Markup Language/Lesson 6/Slide 37 of 45
Displaying Data with XSLT

Task 3: Identify the …in a tabular format. (Contd.)

Result:
 In the given scenario, you can use the TABLE, TR, TH, and
  TD elements in an XSLT style sheet to display data in a
  tabular format.




   ©NIIT               eXtensible Markup Language/Lesson 6/Slide 38 of 45
Displaying Data with XSLT

Task 4: Identify a mechanism to create a comma-
separated list of values.
Result
 In order to create a comma-separated list of values, you
  can use either the template or the for-each element.




   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 39 of 45
Displaying Data with XSLT


Task 5:Create a style sheet.


Task 6:Apply the style sheet to the XML
  document.


Task 7:View the XML document.




©NIIT              eXtensible Markup Language/Lesson 6/Slide 40 of 45
Displaying Data with XSLT

Problem Statement 6.P.1
 The details about suppliers who supply various products to
 CyberShoppe need to be displayed in a tabular format.
 Supplier details include supplier ID, first name, last name,
 address, phone number, and various products supplied by
 them. A supplier may supply one or more products. The
 names of all products supplied by a supplier must be
 displayed in a single column in the form of a
 comma-separated list. The details in every alternate row in
 the table must be displayed in red.
 Hint: Use the mod operator of XPath for checking for an
 alternate row.




  ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 41 of 45
Displaying Data with XSLT

Creating Nested Style Sheets
The import Element
 The import element is an element supported by XSLT in
  which one XSLT style sheet can be reused by another
  XSLT style sheet.
 The general form of the import element is as follows:
   xsl:import href=location/
 The import element is a top level element that must appear
  immediately after the stylesheet element.




   ©NIIT                eXtensible Markup Language/Lesson 6/Slide 42 of 45
Displaying Data with XSLT
Summary
In this lesson, you learned that:
 There are two elements in XSLT that allow you to format
  data based on a condition. They are if and choose.
 The if element provides a simple if-then construct. It has
  a single test attribute, which specifies the criteria for
  performing an action.
 The choose element selects one from a number of
  possible alternatives. It consists of a number of when
  elements followed by an optional otherwise element.
 XPath is a language used for searching and retrieving
  information from an XML document.
 The primary purpose of XPath is to address parts of an
  XML document, and manipulate strings, numbers, and
  boolean values.
  ©NIIT                  eXtensible Markup Language/Lesson 6/Slide 43 of 45
Displaying Data with XSLT

Summary (Contd.)
 XPath expressions can match specific patterns, retrieve
  results, and perform additional operations relative to the
  context of the returned nodes.
 XPath provides functions, which can be categorized as
  follows:
    String functions: Used for basic string operations, such
     as finding a string's length or changing a string from
     uppercase to lowercase.
    Node-set functions: Used to manipulate node sets or
     return information about node sets.
    Boolean functions: Return either true or false based on
     the argument passed to the function.
    Numeric functions: Used to perform calculations on
     numeric values.
  ©NIIT                eXtensible Markup Language/Lesson 6/Slide 44 of 45
Displaying Data with XSLT

Summary (Contd.)
 You can use HTML code in an XSLT style sheet to display
  data in different formats.
 The import element is used to import an XSLT style
  sheet to another XSLT style sheet.




  ©NIIT               eXtensible Markup Language/Lesson 6/Slide 45 of 45

More Related Content

What's hot

Object oriented database model
Object oriented database modelObject oriented database model
Object oriented database modelPAQUIAAIZEL
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Rakibul Hasan Pranto
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMSkoolkampus
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faqxavier john
 
Xml viva questions
Xml viva questionsXml viva questions
Xml viva questionsVipul Naik
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based ApplicationsPrabu U
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMSkoolkampus
 
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapOverview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapVikas Jagtap
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization TechniquesNishant Munjal
 
Module 5 oodb systems semantic db systems
Module 5 oodb systems  semantic db systemsModule 5 oodb systems  semantic db systems
Module 5 oodb systems semantic db systemsTaher Barodawala
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbmsmaryeem
 
PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)Buck Woolley
 
Rendering XML Documents
Rendering XML DocumentsRendering XML Documents
Rendering XML Documentsyht4ever
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structuresKrishna Nanda
 

What's hot (20)

Chapt 1 odbms
Chapt 1 odbmsChapt 1 odbms
Chapt 1 odbms
 
Object oriented database model
Object oriented database modelObject oriented database model
Object oriented database model
 
Object oriented data model
Object oriented data modelObject oriented data model
Object oriented data model
 
Structures
StructuresStructures
Structures
 
03 x files
03 x files03 x files
03 x files
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
12 SQL
12 SQL12 SQL
12 SQL
 
Xml viva questions
Xml viva questionsXml viva questions
Xml viva questions
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based Applications
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS
 
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtapOverview of Object-Oriented Concepts Characteristics by vikas jagtap
Overview of Object-Oriented Concepts Characteristics by vikas jagtap
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
Module 5 oodb systems semantic db systems
Module 5 oodb systems  semantic db systemsModule 5 oodb systems  semantic db systems
Module 5 oodb systems semantic db systems
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
 
PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)PBDJ 19-4(woolley rev)
PBDJ 19-4(woolley rev)
 
Rendering XML Documents
Rendering XML DocumentsRendering XML Documents
Rendering XML Documents
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 

Similar to 03 sm3 xml_xp_06

Xml session07
Xml session07Xml session07
Xml session07Niit Care
 
01 sm3 xml_xp_02
01 sm3 xml_xp_0201 sm3 xml_xp_02
01 sm3 xml_xp_02Niit Care
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Documentyht4ever
 
285109443-SAP-BW-Info-Object.ppt
285109443-SAP-BW-Info-Object.ppt285109443-SAP-BW-Info-Object.ppt
285109443-SAP-BW-Info-Object.pptntrnbk
 
Using the BizTalk Mapper
Using the BizTalk MapperUsing the BizTalk Mapper
Using the BizTalk MapperDaniel Toomey
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08Niit Care
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTDudy Ali
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
 
CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++Prof Ansari
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++Hoang Nguyen
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxsimonlbentley59018
 

Similar to 03 sm3 xml_xp_06 (20)

Xml session07
Xml session07Xml session07
Xml session07
 
01 sm3 xml_xp_02
01 sm3 xml_xp_0201 sm3 xml_xp_02
01 sm3 xml_xp_02
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
Session 4
Session 4Session 4
Session 4
 
Oops recap
Oops recapOops recap
Oops recap
 
285109443-SAP-BW-Info-Object.ppt
285109443-SAP-BW-Info-Object.ppt285109443-SAP-BW-Info-Object.ppt
285109443-SAP-BW-Info-Object.ppt
 
Using the BizTalk Mapper
Using the BizTalk MapperUsing the BizTalk Mapper
Using the BizTalk Mapper
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLT
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
Tp2
Tp2Tp2
Tp2
 
Op ps
Op psOp ps
Op ps
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
 
Xml session
Xml sessionXml session
Xml session
 
Jazz
JazzJazz
Jazz
 

More from Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Recently uploaded

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

03 sm3 xml_xp_06

  • 1. Displaying Data with XSLT Objectives In this lesson, you will learn to: Perform conditional formatting in a style sheet Use XPath pattern matching in a style sheet Create a comma-separated list of values Import a style sheet in another style sheet ©NIIT eXtensible Markup Language/Lesson 6/Slide 1 of 45
  • 2. Displaying Data with XSLT Problem Statement 6.D.1 A list of products sold at CyberShoppe needs to be displayed. These products need to be categorized based on their prices. The details about products priced higher than $50 are to be displayed in red and the rest are to be displayed in green. The details to be displayed include the product name, description, price, and quantity on hand. ©NIIT eXtensible Markup Language/Lesson 6/Slide 2 of 45
  • 3. Displaying Data with XSLT Task List Identify data to be displayed. Identify the elements required to format data based on a condition. Create a style sheet to format data based on a condition. Apply the style sheet to the XML document. View the XML document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 3 of 45
  • 4. Displaying Data with XSLT Task 1: Identify data to be displayed. Result As per the scenario, the data that has to be displayed is as follows: PRODUCTNAME DESCRIPTION PRICE QUANTITY ©NIIT eXtensible Markup Language/Lesson 6/Slide 4 of 45
  • 5. Displaying Data with XSLT Task 2: Identify the elements required to format data based on a condition. The if Element The if element provides a simple if-then construct. The syntax of if element is as follows: xsl:if test=“condition” [actions to be performed if the condition is true] /xsl:if ©NIIT eXtensible Markup Language/Lesson 6/Slide 5 of 45
  • 6. Displaying Data with XSLT Task 2: Identify the elements …a condition. (Contd.) The choose Element The choose element is used to make a choice when there are two or more possible courses of action. It provides a means for testing multiple conditions. ©NIIT eXtensible Markup Language/Lesson 6/Slide 6 of 45
  • 7. Displaying Data with XSLT Task 2: Identify the elements …a condition. (Contd.) The syntax of the choose element is as follows: xsl:choose xsl:when test=condition [action to be taken] /xsl:when : : xsl:otherwise [action to be taken] /xsl:otherwise /xsl:choose ©NIIT eXtensible Markup Language/Lesson 6/Slide 7 of 45
  • 8. Displaying Data with XSLT Task 2: Identify the elements …a condition. (Contd.) The following table lists the comparison and boolean operators that can be used with the xsl:choose and xsl:if elements: Operator Meaning Example = Equal to PRICE[. = 20] PRODUCTNAME[. = ‘Mini Bus’] != Not equal to PRICE[. != 20] PRODUCTNAME[. != ‘Barbie Doll’] lt; Less than PRICE[. lt; 20] gt; Greater than PRICE[. gt; 20] lt;= Less than or equal to PRICE[. lt;= 20] gt;= Greater than or equal to PRICE[. gt;= 20] ©NIIT eXtensible Markup Language/Lesson 6/Slide 8 of 45
  • 9. Displaying Data with XSLT Task 2: Identify the elements … a condition. (Contd.) Operator Meaning Example and Logical AND PRICE[. gt 20 and . lt; 30] or Logical OR PRICE[. = 20 or . = 45] not Negation operator PRICE[not(. = 30)] The operators given in bold in the above list are Microsoft extensions to the original list of operators recommended by W3C. ©NIIT eXtensible Markup Language/Lesson 6/Slide 9 of 45
  • 10. Displaying Data with XSLT Task 2: Identify the elements … a condition. (Contd.) Result As the value of the PRICE element needs to be checked for a range of values, the choose element in combination with when and otherwise can be used for performing the check. ©NIIT eXtensible Markup Language/Lesson 6/Slide 10 of 45
  • 11. Displaying Data with XSLT Task 3: Create a style sheet to format data based on a condition. Task 4: Apply the style sheet to the XML document. Task 5: View the XML document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 11 of 45
  • 12. Displaying Data with XSLT Just a Minute… The details about the books sold at CyberShoppe need to be displayed. Books priced higher than $100 are to be displayed in red, those priced higher than $75 are to be displayed in blue, and the rest are to be displayed in green. ©NIIT eXtensible Markup Language/Lesson 6/Slide 12 of 45
  • 13. Displaying Data with XSLT Problem Statement 6.D.2 CyberShoppe needs to display a summarized report about orders. The data about the products and all orders placed for products is stored in an XML document. This data includes the details about a product, such as product ID, product name, and price per unit. For each product, the data about all orders placed against that product is also stored. This data includes the order number, shipping address, and the order quantity. ©NIIT eXtensible Markup Language/Lesson 6/Slide 13 of 45
  • 14. Displaying Data with XSLT Problem Statement 6.D.2 (Contd.) The structure of the XML document is given below: SUMMARY PRODUCT ORDER SHIPPING ADDRESS QUANTITY ©NIIT eXtensible Markup Language/Lesson 6/Slide 14 of 45
  • 15. Displaying Data with XSLT Task List Identify the data to be displayed. Identify a mechanism to display summarized data. Identify the XPath expressions required for performing calculations. Identify the functions required for performing calculations. Create an XSLT style sheet containing XPath patterns and functions. Create the XML document. View the XML document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 15 of 45
  • 16. Displaying Data with XSLT Task 1: Identify the data to be displayed. Result As per the given scenario, the details to be displayed are as follows: Product ID Product Name Price per unit Details about orders placed against the product: ® Order number ® Shipping address ® Total quantity ® Order value Total sales amount for the product ©NIIT eXtensible Markup Language/Lesson 6/Slide 16 of 45
  • 17. Displaying Data with XSLT Task 2: Identify a mechanism to display summarized data. XML Path (XPath) language is used for searching and retrieving information from an XML file. XPath treats an XML document as a tree of interrelated branches and nodes. A node can be of any type, such as an element, attribute, processing instruction (PI), comment, text, or namespace. XPath provides a set of expressions and functions that can be used for matching nodes in an XML document. As a result of matching nodes with a specific pattern, a set of nodes referred to as node set is retrieved. ©NIIT eXtensible Markup Language/Lesson 6/Slide 17 of 45
  • 18. Displaying Data with XSLT Task 2: Identify a … summarized data. (Contd.) Result As XPath provides a set of expressions and functions that can match specific patterns, retrieve results, and perform additional operations such as calculations, XPath can be used along with XSLT for displaying data in the given scenario. ©NIIT eXtensible Markup Language/Lesson 6/Slide 18 of 45
  • 19. Displaying Data with XSLT Task 3: Identify the XPath expressions required for performing calculations. XPath expressions can be used to retrieve data based on specific conditions. You can apply constraints by adding a filter clause, which is otherwise referred to as a filter pattern. Using XPath, you can create expressions that can identify the nodes in an XML document based on names and values. You can also create expressions that identify the relationship of a node with other nodes in the document. These expressions can be used with XSLT patterns for matching and retrieving nodes. XPath expressions work on the basis of a specific context. XPath expressions can be created using a set of operators and special characters. The following table describes these operators: ©NIIT eXtensible Markup Language/Lesson 6/Slide 19 of 45
  • 20. Displaying Data with XSLT Task 3: Identify the … performing calculations. (Contd.) Operator/ Example Description Special Character / /PRODUCTDATA Selects immediate child elements of PRODUCTDATA. If this operator occurs at the start of the pattern, it indicates that the child elements should be selected from the root node. // //PRODUCTNAME Searches for the specified element at any node level. . .PRODUCTNAME Indicates the current context. * * Selects all elements regardless of the element name. @ @PRODUCTID Used as a prefix for the attribute PRODUCTID. ©NIIT eXtensible Markup Language/Lesson 6/Slide 20 of 45
  • 21. Displaying Data with XSLT Task 3: Identify the … performing calculations. (Contd.) Operator/ Example Description Special Character @* @* Selects all attributes, regardless of the name. : : Separates the namespace prefix from the element or attribute name. () (PRICE*QUANTITY) Used to group operations. [] [@PRODUCTID='P001'] Applies a filter pattern. + num1 + num2 Adds two numbers, returning their sum. - num1 - num2 Subtracts num2 from num1, returning the difference. ©NIIT eXtensible Markup Language/Lesson 6/Slide 21 of 45
  • 22. Displaying Data with XSLT Task 3: Identify the …performing calculations. (Contd.) Operator/ Example Description Special Character * num1 * num2 Multiplies num1 by num2, returning the product. div num1 div num2 Divides num1 by num2, returning the quotient. mod num1 mod num2 Returns the modulus—that is, divides num1 by num2 and returns the remainder. .. ../PRODUCTNAME Selects the PRODUCTNAME element, which exists within the parent of the current element. ©NIIT eXtensible Markup Language/Lesson 6/Slide 22 of 45
  • 23. Displaying Data with XSLT Task 3: Identify the … performing calculations. (Contd.) Result In the given scenario, an XPath expression can be created for calculating the order value: xsl:value-of select='(../@PRICE) * (QUANTITY)'/ The above expression instructs the XSLT processor to pick up the value of the PRICE attribute of the parent element and multiply it by the value of the QUANTITY element. ©NIIT eXtensible Markup Language/Lesson 6/Slide 23 of 45
  • 24. Displaying Data with XSLT Task 4: Identify the functions required for performing calculations. XPath functions XPath provides a various categories of functions. They are: string node set boolean number These functions can take one or more arguments. ©NIIT eXtensible Markup Language/Lesson 6/Slide 24 of 45
  • 25. Displaying Data with XSLT Task 4: Identify the ... performing calculations. (Contd.) String functions The string functions of XPath are used to perform string operations, such as finding the length of a string or converting a string from uppercase to lowercase. Some of the string functions provided in XPath are: string(obj?): Converts the argument to a string value. starts-with(str, str): Returns true if the first string begins with the second string contains(str, str): Returns true if the first string contains the second string. ©NIIT eXtensible Markup Language/Lesson 6/Slide 25 of 45
  • 26. Displaying Data with XSLT Task 4: Identify the … performing calculations. (Contd.) String functions (Contd.) substring(str, num, num?): Returns a portion of the string starting from the position specified in the second argument. Returns the number of characters specified in the third argument. substring-before(str, str): Returns the portion of the first string that precedes the second string. substring-after(str, str): Returns the portion of the first string that follows the second string. string-length(str?): Returns the length of the string. ©NIIT eXtensible Markup Language/Lesson 6/Slide 26 of 45
  • 27. Displaying Data with XSLT Task 4: Identify the … performing calculations. (Contd.) Node-Set functions Node-set functions are used to manipulate node sets or to return information about node sets. Some of the node-set functions provided in XPath are: last(): Returns the number of the last node in the current node-set. position(): Returns the position of the current node within the parent node. count(ns): Returns the number of occurrences of the specified node-set. id(obj): Returns the element with the specified unique ID. ©NIIT eXtensible Markup Language/Lesson 6/Slide 27 of 45
  • 28. Displaying Data with XSLT Task 4: Identify the … performing calculations. (Contd.) Boolean functions All boolean functions return either true or false. Some of the node-set functions provided in XPath are: boolean(obj?): Converts the argument to a boolean. not(boolean): Takes an expression, which returns a boolean value, as its argument. Negates the result of the Boolean expression. ©NIIT eXtensible Markup Language/Lesson 6/Slide 28 of 45
  • 29. Displaying Data with XSLT Task 4: Identify the … performing calculations. (Contd.) Numeric functions XPath provides numeric functions for various purposes, such as adding numbers, finding the nearest integer value, and converting strings to numbers. Some of the numeric function provided in XPath are: number(obj?): Converts the argument to a number. sum(ns): Sums up the values of the nodes contained in the node-set, which is passed as an argument to the function. floor(num): Returns the largest integer that is less than or equal to the argument. ceiling(num): Returns the smallest integer that is greater than or equal to the argument. ©NIIT eXtensible Markup Language/Lesson 6/Slide 29 of 45
  • 30. Displaying Data with XSLT Task 4: Identify the … performing calculations. (Contd.) round(num): Rounds up the number to the nearest integer. Result As per the scenario, the sum() function of XPath needs to be used for calculating the product sales value of each product. The code for calculating the product sales values is given as follows: xsl:value-of select='(../@PRICE) * (QUANTITY)'/ xsl:value-of select='(./@PRICE) * sum(./ORDER/QUANTITY)'/ ©NIIT eXtensible Markup Language/Lesson 6/Slide 30 of 45
  • 31. Displaying Data with XSLT Task 5: Create an XSLT style sheet containing XPath patterns and functions. Task 6: Create the XML document. Task 7: View the XML document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 31 of 45
  • 32. Displaying Data with XSLT Problem Statement 6.D.3 The details about the books that are available for sale at CyberShoppe are stored in an XML document. The book details, such as book ID, title, rate, author first name, and author last name should be displayed in a tabular format. The first name and last name of an author should be displayed in a single column, AUTHOR(S). If a book has multiple authors, their names should be displayed as comma-separated values. ©NIIT eXtensible Markup Language/Lesson 6/Slide 32 of 45
  • 33. Displaying Data with XSLT Task List Identify the data to be displayed. Identify a mechanism to be used to display the data in a tabular format. Identify the elements required to display data in a tabular format. Identify a mechanism to create a comma-separated list of values. Create a style sheet. Apply the style sheet to the XML document. View the XML document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 33 of 45
  • 34. Displaying Data with XSLT Task 1: Identify the data to be displayed. Result In the given scenario, the data to be displayed is as follows: BOOKID TITLE RATE AUTHOR FIRSTNAME LASTNAME ©NIIT eXtensible Markup Language/Lesson 6/Slide 34 of 45
  • 35. Displaying Data with XSLT Task 2: Identify a mechanism to be used to display the data in a tabular format. Information pertaining to the way in which XML data must appear in a browser is specified in either CSS or XSLT style sheets. However, in certain situations, these two methods do not have the capability to display data in certain formats. You can combine the features of HTML and XSLT to format the data from an XML document as per requirements. ©NIIT eXtensible Markup Language/Lesson 6/Slide 35 of 45
  • 36. Displaying Data with XSLT Task 2: Identify a mechanism …the data in a tabular format. (Contd.) Result: In the given scenario, HTML tags can be used in an XSLT to display data in a tabular format. ©NIIT eXtensible Markup Language/Lesson 6/Slide 36 of 45
  • 37. Displaying Data with XSLT Task 3: Identify the elements required to display data in a tabular format. Using HTML Elements in an XSLT Style Sheet In order to use HTML tags in an XSLT style sheet, you must write the HTML code to display the data in the desired format. This code is then embedded in the XSLT document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 37 of 45
  • 38. Displaying Data with XSLT Task 3: Identify the …in a tabular format. (Contd.) Result: In the given scenario, you can use the TABLE, TR, TH, and TD elements in an XSLT style sheet to display data in a tabular format. ©NIIT eXtensible Markup Language/Lesson 6/Slide 38 of 45
  • 39. Displaying Data with XSLT Task 4: Identify a mechanism to create a comma- separated list of values. Result In order to create a comma-separated list of values, you can use either the template or the for-each element. ©NIIT eXtensible Markup Language/Lesson 6/Slide 39 of 45
  • 40. Displaying Data with XSLT Task 5:Create a style sheet. Task 6:Apply the style sheet to the XML document. Task 7:View the XML document. ©NIIT eXtensible Markup Language/Lesson 6/Slide 40 of 45
  • 41. Displaying Data with XSLT Problem Statement 6.P.1 The details about suppliers who supply various products to CyberShoppe need to be displayed in a tabular format. Supplier details include supplier ID, first name, last name, address, phone number, and various products supplied by them. A supplier may supply one or more products. The names of all products supplied by a supplier must be displayed in a single column in the form of a comma-separated list. The details in every alternate row in the table must be displayed in red. Hint: Use the mod operator of XPath for checking for an alternate row. ©NIIT eXtensible Markup Language/Lesson 6/Slide 41 of 45
  • 42. Displaying Data with XSLT Creating Nested Style Sheets The import Element The import element is an element supported by XSLT in which one XSLT style sheet can be reused by another XSLT style sheet. The general form of the import element is as follows: xsl:import href=location/ The import element is a top level element that must appear immediately after the stylesheet element. ©NIIT eXtensible Markup Language/Lesson 6/Slide 42 of 45
  • 43. Displaying Data with XSLT Summary In this lesson, you learned that: There are two elements in XSLT that allow you to format data based on a condition. They are if and choose. The if element provides a simple if-then construct. It has a single test attribute, which specifies the criteria for performing an action. The choose element selects one from a number of possible alternatives. It consists of a number of when elements followed by an optional otherwise element. XPath is a language used for searching and retrieving information from an XML document. The primary purpose of XPath is to address parts of an XML document, and manipulate strings, numbers, and boolean values. ©NIIT eXtensible Markup Language/Lesson 6/Slide 43 of 45
  • 44. Displaying Data with XSLT Summary (Contd.) XPath expressions can match specific patterns, retrieve results, and perform additional operations relative to the context of the returned nodes. XPath provides functions, which can be categorized as follows: String functions: Used for basic string operations, such as finding a string's length or changing a string from uppercase to lowercase. Node-set functions: Used to manipulate node sets or return information about node sets. Boolean functions: Return either true or false based on the argument passed to the function. Numeric functions: Used to perform calculations on numeric values. ©NIIT eXtensible Markup Language/Lesson 6/Slide 44 of 45
  • 45. Displaying Data with XSLT Summary (Contd.) You can use HTML code in an XSLT style sheet to display data in different formats. The import element is used to import an XSLT style sheet to another XSLT style sheet. ©NIIT eXtensible Markup Language/Lesson 6/Slide 45 of 45