SlideShare a Scribd company logo
1 of 46
Rendering XML Documents


Objectives
In this session, you will learn to:
Define rendering
Identify the need for style sheets
Create a cascading style sheet
Create an XSLT for formatting data




©NIIT                    eXtensible Markup Language/Lesson 5/Slide 1 of 46
Rendering XML Documents


Rendering XML documents
Rendering refers to the act of processing an XML
 document so that it can be displayed on a variety of
 targets, such as Web browsers, e-mail, pagers, and
 cellular phones.
Style Sheets
A style sheet is a document that contains formatting
 rules for one or more XML documents.
It contains the code to instruct the Web browser on
 how to translate the structure of the source document
 into a structure that can be displayed.


©NIIT                 eXtensible Markup Language/Lesson 5/Slide 2 of 46
Rendering XML Documents

What does a Style Sheet Allow you to do?
 A style sheet allows you to perform the following tasks:
     Transform an XML document into another structure for
      the purpose of rendering it to a specific target. This may
      include:
           Generating constant text, such as labels and
            headings
           Specifying filters for extracting the required data
           Changing the sequence of elements and attributes
           Sorting the content
           Performing complex transformations that compute
            values based on the existing content


©NIIT                        eXtensible Markup Language/Lesson 5/Slide 3 of 46
Rendering XML Documents


What does a Style Sheet Allow you to do? (Contd.)
     Describe how to present the transformed information.
      Description of presentation includes:
           Screen or page layout
           Assignment of transformed content into lists and
            paragraphs
           Specification of properties such as spacing,
            margins, alignment, and fonts




©NIIT                     eXtensible Markup Language/Lesson 5/Slide 4 of 46
Rendering XML Documents


Problem Statement 5.D.1
CyberShoppe wants to display the details of all the
 products that it sells. The product details need to be
 displayed in a browser in the format specified below:
     The price per unit, description, and quantity on
      hand for each product should be displayed in teal
      color with a font size of 10 pts.
     The name of the product must be displayed in red
      with a font size of 20 pts. It should be displayed in
      bold.
     All details must be displayed in the Arial font.



©NIIT                    eXtensible Markup Language/Lesson 5/Slide 5 of 46
Rendering XML Documents


Task List
Identify the elements to be displayed.
Identify a mechanism to display formatted data.
Create a style sheet to format data.
Apply the style sheet to the XML document.
View the document in a browser.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 6 of 46
Rendering XML Documents


Task 1:Identify the elements to be displayed.
Result
As per the given scenario, the elements that have to
 be displayed are:
     PRODUCTNAME
     PRICE
     DESCRIPTION
     QUANTITY




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 7 of 46
Rendering XML Documents


Task 2:Identify a mechanism to display formatted
data.
Cascading Style Sheets (CSS)
     A Cascading Style Sheet (CSS) is a type of style
      sheet that provides a simple mechanism for adding
      styles to an XML or HTML document.
     A CSS is a text file containing one or more rules or
      definitions for the style characteristics of a particular
      element.
     The CSS file can be included in a number of XML
      documents that have the same data structure.



©NIIT                    eXtensible Markup Language/Lesson 5/Slide 8 of 46
Rendering XML Documents


Task 2:Identify a mechanism to display formatted
data. (Contd.)
Result
     As CSS allows you to format data in an XML
      document, CSS can be used to display the products
      data stored in the XML document in the specified
      format.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 9 of 46
Rendering XML Documents


Task 3:Create a style sheet to format data.
CSS allows you to format the contents of a document
 by specifying the element name followed by the
 formatting instructions for that element. The syntax for
 coding a CSS is as follows:
  elementname
  {
        property1: value;
        property2: value;
        property3: value;
  }

©NIIT                 eXtensible Markup Language/Lesson 5/Slide 10 of 46
Rendering XML Documents


Task 3:Create a style sheet to format data.
  (Contd.)
Action
Type the code for creating the style sheet and
 save the file as product.css.




©NIIT               eXtensible Markup Language/Lesson 5/Slide 11 of 46
Rendering XML Documents


Task 4:Apply the style sheet to the XML
document.
In order to apply the formatting specifications given in
 the CSS file to the data in an XML document, you need
 to associate the CSS with the XML document.
This can be done using the following syntax:
    <?xml:stylesheet type="text/css" href="path-name"?>




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 12 of 46
Rendering XML Documents


Task 5:View the document in a browser.




©NIIT             eXtensible Markup Language/Lesson 5/Slide 13 of 46
Rendering XML Documents


Just a Minute…
The details about all the books sold at CyberShoppe
 are to be displayed in the following format:
     The book name is to be displayed in blue, Times
      New Roman, size 20pts, and bold.
     The first name and last name of the author are to be
      displayed in green, Arial, and size 10pts.
     Price of the book is to be displayed in red, Times
      New Roman, and size 20pts.
Create a CSS for displaying the book details in the
 above format.


©NIIT                  eXtensible Markup Language/Lesson 5/Slide 14 of 46
Rendering XML Documents


Problem Statement 5.D.2
CyberShoppe needs to display product details, such
 as product ID, name of the product, and price per unit.
  In the output, all details about products should be
  displayed in red.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 15 of 46
Rendering XML Documents


Task List
Identify the data to be displayed.
Identify a mechanism for displaying selective data in a
 sorted order.
Identify the elements required to display selective data
 in a sorted order.
Create a style sheet.
Apply the style sheet to the XML document.
View the XML document.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 16 of 46
Rendering XML Documents


Task 1:Identify the data to be displayed.
Result
As per the given scenario, the data that is to be
 displayed is as follows:
     PRODID
     PRODUCTNAME
     PRICE




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 17 of 46
Rendering XML Documents


Task 2:Identify a mechanism for displaying
selective data in a sorted order.
CSS does not support operations, such as reordering
 and sorting elements based on a condition, and
 displaying only selective elements.
To help you perform such operations, XML supports
 another style sheet language called eXtensible Style
 Sheet Language (XSL).
XSL is made up of the following parts:
     XSL Transformations (XSLT): It is an XML-based
      language that allows you to transform an XML
      document into another XML document.

©NIIT                eXtensible Markup Language/Lesson 5/Slide 18 of 46
Rendering XML Documents


Task 2:Identify a mechanism for…(Contd.)
     XML Path (XPath): It is a language that is used to
      access different parts of an XML document, such
      as elements and attributes.
XSL uses XSLT to transform an XML document that
 contains data.
XSLT contains instructions for specifying how an XML
 document is to be transformed.
XSLT uses XPath expressions to extract specific data
 from an XML document.




©NIIT                  eXtensible Markup Language/Lesson 5/Slide 19 of 46
Rendering XML Documents


Task 2:Identify a mechanism for…(Contd.)
A software called XSLT processor reads the
 instructions given in XSLT and transforms the XML
 document into another XML document, which uses
 formatting objects of XSL to display the XML
 document in the desired format.




©NIIT                eXtensible Markup Language/Lesson 5/Slide 20 of 46
Rendering XML Documents


Task 2:Identify a mechanism for…(Contd.)
Comparison between XSLT and CSS
XSLT is a superset of the CSS functionality.
XSLT is an application of XML. Therefore, it follows
 the XML syntax, whereas CSS has its own syntax.
 XML and CSS can co-exist since they meet different
 needs.
XSLT is intended for complex formatting.




©NIIT                eXtensible Markup Language/Lesson 5/Slide 21 of 46
Rendering XML Documents


Task 2:Identify a mechanism for…(Contd.)
Working of the XSLT Processor

                                 MSXML Parser
        XSLT style sheet            XSLT tree




                                     XSLT                     Result tree
                                    processo
                                       r



        XML document               Source tree




©NIIT                      eXtensible Markup Language/Lesson 5/Slide 22 of 46
Rendering XML Documents


Task 2:Identify a mechanism for…(Contd.)
Result
Since XSL gives you added functionality of extracting
 specific data from an XML document, XSL can be
 used to select data as per the scenario.
You need to use XSLT, which is a part of XSL, to
 create a style sheet. This style sheet should contain
 the instructions for transformation of an XML
 document into the result tree.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 23 of 46
Rendering XML Documents


Task 3:Identify the elements required to display
selective data in a sorted order.
XSLT provides a number of elements for selecting
 and formatting data.
Some of the XSLT elements are:
     stylesheet
     value-of
     for-each
     sort
     text


©NIIT                eXtensible Markup Language/Lesson 5/Slide 24 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The stylesheet element
     Since an XSLT style sheet contains instructions for
      transforming XML documents, a declaration is
      added in the XSLT file to instruct the browser that it
      is a style sheet file. This declaration is known as
      style sheet declaration.
     The syntax for style sheet declaration is as follows:
  <xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSLTransform"
  version=”1.0”>



©NIIT                  eXtensible Markup Language/Lesson 5/Slide 25 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The value-of element
     This element displays the value of the element or
      attribute specified. The syntax for using this
      element is as follows:
    <xsl:value-of select="elementname|attributename" />
     If you want to display the value of an attribute, you
      must use the “@” symbol as a prefix with the
      attribute name.




©NIIT                  eXtensible Markup Language/Lesson 5/Slide 26 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The for-each element
     This element is used to instruct the XSLT
      processor to process the information for each
      instance of the specified pattern.
     The syntax for using the for-each element is as
      follows:
    <xsl:for-each select="pattern">
    [action to be performed]
    </xsl:for-each>



©NIIT                  eXtensible Markup Language/Lesson 5/Slide 27 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The for-each element (Contd.)
     The select attribute of the for-each element
      allows you to specify the elements or attributes on
      which the action needs to be performed.
     The XSLT transformation instructions within the
      for-each element are applied to each of the
      nodes selected by the select attribute of the for-
      each element.




©NIIT                  eXtensible Markup Language/Lesson 5/Slide 28 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The sort element
     XSLT provides the sort element for sorting data
      based on values assigned to elements and
      attributes.
     The sort element does not contain any child
      elements.
     This element is always used as a child of the for-
      each element or the apply-templates element.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 29 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The sort element (Contd.)
     The syntax for using the sort element is as
      follows:
        <xsl:sort select="expression"
        order="ascending|descending"
        case-order="upper-first|lower-first“
        data-type="text|number|qname"/>




©NIIT                    eXtensible Markup Language/Lesson 5/Slide 30 of 46
Rendering XML Documents


Task 3:Identify the…sorted order. (Contd.)
The text element
     The text element allows you to generate constant
      text in the output.
     This element can be used to display labels.




©NIIT                 eXtensible Markup Language/Lesson 5/Slide 31 of 46
Rendering XML Documents


XSLT Template Rules
XSLT allows you to define template rules for the
 output.
A template rule describes how an XML element and
 its contents are converted into a format that can be
 displayed in the browser.
A template rule consists of two parts:
           A pattern that identifies an XML element in an
            XML document.
           An action or processing code that details the
            transformation and rendering of the resulting
            element.

©NIIT                     eXtensible Markup Language/Lesson 5/Slide 32 of 46
Rendering XML Documents


XSLT Template Rules (Contd.)
XSLT uses two main elements for creating template
 rules, template and apply-templates.
The template Element
     The template element is used to define a
      template for the desired output. The syntax for
      using this element is as follows:
    <xsl:template match="pattern">
    [action to be taken]
    </xsl:template>



©NIIT                  eXtensible Markup Language/Lesson 5/Slide 33 of 46
Rendering XML Documents


XSLT Template Rules (Contd.)
The apply-templates Element
     This element is used to instruct the XSLT
      processor to find an appropriate template and
      perform the specified tasks on each selected
      element.
     The syntax for using this element is as follows:
        <xsl:apply-templates [select="pattern"]>
     The select attribute is optional and is used to
      specify the context in which the template should be
      executed.


©NIIT                   eXtensible Markup Language/Lesson 5/Slide 34 of 46
Rendering XML Documents


XSLT Template Rules (Contd.)
The apply-templates Element (Contd.)
     You can effectively use templates in order to display
      data.
     The XSLT processor always starts processing from
      the root element. Therefore, it starts processing from
      the template rule <xsl:template match=“/”>.
     If you have more than one template rule created for
      the same element, the previous template rule will be
      overridden by the other template.




 ©NIIT                  eXtensible Markup Language/Lesson 5/Slide 35 of 46
Rendering XML Documents

XSLT Template Rules (Contd.)




  ©NIIT            eXtensible Markup Language/Lesson 5/Slide 36 of 46
Rendering XML Documents

XSLT Template Rules (Contd.)
Default Template
To prevent the processing of templates from stalling
 when there is no suitable selection rule, the XSLT
 processor assumes a default template rule.




 ©NIIT                eXtensible Markup Language/Lesson 5/Slide 37 of 46
Rendering XML Documents

XSLT Template Rules (Contd.)
Default Template (Contd.)
 The default template rule consists of the following statements:
    <xsl:template match= "/">
    <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="*">
    <xsl:apply-templates />
    </xsl:template>
    <xsl:template match="text()">
    <xsl:value-of select=".">
    </xsl:template>
 ©NIIT                   eXtensible Markup Language/Lesson 5/Slide 38 of 46
Rendering XML Documents

Task 3:Identify the…sorted order. (Contd.)
Result
The following XSLT elements are used to extract and
 format the required data:
     stylesheet: To specify the style sheet declaration.
     for-each: To display the product ID, product name,
      and price for each instance of the product element.
     value-of: To display the values of PRODID,
      PRODUCTNAME, and PRICE.
     sort: To sort the elements and attributes containing
      product details based on the product ID.
     text: To display the labels for various elements and
      attributes.
     template: To be used as the parent element of the for-
      each element.
 ©NIIT                  eXtensible Markup Language/Lesson 5/Slide 39 of 46
Rendering XML Documents


Task 4:Create a style sheet.
Action
As per the scenario, the product details, such as
 PRODUCTID, PRODUCTNAME, and PRICE have to be
 sorted in the ascending order of the PRODID attribute.
To do this, type the necessary code as save the file as
 product1.xsl.




 ©NIIT                 eXtensible Markup Language/Lesson 5/Slide 40 of 46
Rendering XML Documents


Task 5:Apply the style sheet to the XML
document.
To view selective details of a product, such as product
 ID, name, and rate from an XML document, you need to
 associate the XML document with the XSL file that
 renders the required data.
This can be done using the following syntax:
    <?xml:stylesheet type="text/xsl" href="path-name"?>
Action
Type the code for creating the XML document as save
 the file as product.xml.



 ©NIIT                 eXtensible Markup Language/Lesson 5/Slide 41 of 46
Rendering XML Documents


Task 6:View the XML document.




 ©NIIT            eXtensible Markup Language/Lesson 5/Slide 42 of 46
Rendering XML Documents


Problem Statement 5.P.1
CyberShoppe wants to display the details of all books
 to its customers. The book details that have to be
 displayed are book ID, title, and rate of books. The
 book details must be displayed in the ascending order
 of rate and book ID.




©NIIT                eXtensible Markup Language/Lesson 5/Slide 43 of 46
Rendering XML Documents


Summary
In this lesson you learned that:
Rendering is the process of presenting the data in an
 XML document in different formats.
A style sheet is a separate document that contains the
 formatting rules for one or several XML documents.
There are two types of style sheets used with XML
 documents. They are:
     Cascading Style Sheets (CSS)
     eXtensible Stylesheet Language (XSL)



©NIIT                  eXtensible Markup Language/Lesson 5/Slide 44 of 46
Rendering XML Documents

Summary (Contd.)
CSS is used to define the style or appearance of an
 XML document.
XSL is made up of XSL Transformations (XSLT) and
 XML Path (XPath).
XSLT is a superset of the CSS functionality.
XSLT is used to display selective elements or
 attributes, sort data on one or more elements, and
 process the data on the basis of a condition.
XSLT elements, such as template, apply-
 templates, sort, for-each, and value-of are
 used to extract and format data.

©NIIT                eXtensible Markup Language/Lesson 5/Slide 45 of 46
Rendering XML Documents


Summary (Contd.)
An XSLT style sheet contains a set of templates rules.
 A template rule describes how an XML element and
 its contents are converted into a format that can be
 displayed in the browser.
Each template rule has two parts: a pattern and an
 action.
The reference to a style sheet file is included in an
 XML document by using the syntax
<?xml:stylsheet type="text/css or xsl" href="path-
  name"?>



©NIIT                  eXtensible Markup Language/Lesson 5/Slide 46 of 46

More Related Content

What's hot

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
 
Object oriented database model
Object oriented database modelObject oriented database model
Object oriented database modelPAQUIAAIZEL
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based ApplicationsPrabu U
 
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
 
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
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbmsmaryeem
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMSkoolkampus
 
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
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization TechniquesNishant Munjal
 

What's hot (20)

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)
 
Introduction to odbms
Introduction to odbmsIntroduction to odbms
Introduction to odbms
 
Chapt 1 odbms
Chapt 1 odbmsChapt 1 odbms
Chapt 1 odbms
 
Structures
StructuresStructures
Structures
 
9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS9. Object Relational Databases in DBMS
9. Object Relational Databases in DBMS
 
Object oriented data model
Object oriented data modelObject oriented data model
Object oriented data model
 
Object oriented database model
Object oriented database modelObject oriented database model
Object oriented database model
 
Building XML Based Applications
Building XML Based ApplicationsBuilding XML Based Applications
Building XML Based Applications
 
Oracle soa xml faq
Oracle soa xml faqOracle soa xml faq
Oracle soa xml faq
 
Xml viva questions
Xml viva questionsXml viva questions
Xml viva questions
 
12 SQL
12 SQL12 SQL
12 SQL
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
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
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
Object Oriented Dbms
Object Oriented DbmsObject Oriented Dbms
Object Oriented Dbms
 
08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS08. Object Oriented Database in DBMS
08. Object Oriented Database in DBMS
 
XML Schemas
XML SchemasXML Schemas
XML Schemas
 
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
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 

Viewers also liked

Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style SheetsSenthil Kumar
 
Css cascading style sheet
Css cascading style sheetCss cascading style sheet
Css cascading style sheetMorvana Bonin
 
Designing Mobile Apps with HTML5 & CSS3
Designing Mobile Apps with HTML5 & CSS3Designing Mobile Apps with HTML5 & CSS3
Designing Mobile Apps with HTML5 & CSS3Johannes Ippen
 

Viewers also liked (6)

Kick start @ css
Kick start @ cssKick start @ css
Kick start @ css
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
basics of css
basics of cssbasics of css
basics of css
 
Css cascading style sheet
Css cascading style sheetCss cascading style sheet
Css cascading style sheet
 
Designing Mobile Apps with HTML5 & CSS3
Designing Mobile Apps with HTML5 & CSS3Designing Mobile Apps with HTML5 & CSS3
Designing Mobile Apps with HTML5 & CSS3
 
Fundamental CSS3
Fundamental CSS3Fundamental CSS3
Fundamental CSS3
 

Similar to 03 sm3 xml_xp_05

Similar to 03 sm3 xml_xp_05 (20)

04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
Rendering XML Documents
Rendering XML DocumentsRendering XML Documents
Rendering XML Documents
 
Do You Speak XML? Part 2
Do You Speak XML? Part 2Do You Speak XML? Part 2
Do You Speak XML? Part 2
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
Xml session05
Xml session05Xml session05
Xml session05
 
Working with xml data
Working with xml dataWorking with xml data
Working with xml data
 
Artefactos biz talk 2006
Artefactos biz talk 2006Artefactos biz talk 2006
Artefactos biz talk 2006
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
IT6801-Service Oriented Architecture
IT6801-Service Oriented ArchitectureIT6801-Service Oriented Architecture
IT6801-Service Oriented Architecture
 
XML, XML Databases and MPEG-7
XML, XML Databases and MPEG-7XML, XML Databases and MPEG-7
XML, XML Databases and MPEG-7
 
XML Unit 01
XML Unit 01XML Unit 01
XML Unit 01
 
Web services Overview in depth
Web services Overview in depthWeb services Overview in depth
Web services Overview in depth
 
01 sm3 xml_xp_01
01 sm3 xml_xp_0101 sm3 xml_xp_01
01 sm3 xml_xp_01
 
XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
 
Unit2_XML_S_SS_US Data_CS19414.pptx
Unit2_XML_S_SS_US Data_CS19414.pptxUnit2_XML_S_SS_US Data_CS19414.pptx
Unit2_XML_S_SS_US Data_CS19414.pptx
 
Full xml
Full xmlFull xml
Full xml
 
Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)
 

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

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

03 sm3 xml_xp_05

  • 1. Rendering XML Documents Objectives In this session, you will learn to: Define rendering Identify the need for style sheets Create a cascading style sheet Create an XSLT for formatting data ©NIIT eXtensible Markup Language/Lesson 5/Slide 1 of 46
  • 2. Rendering XML Documents Rendering XML documents Rendering refers to the act of processing an XML document so that it can be displayed on a variety of targets, such as Web browsers, e-mail, pagers, and cellular phones. Style Sheets A style sheet is a document that contains formatting rules for one or more XML documents. It contains the code to instruct the Web browser on how to translate the structure of the source document into a structure that can be displayed. ©NIIT eXtensible Markup Language/Lesson 5/Slide 2 of 46
  • 3. Rendering XML Documents What does a Style Sheet Allow you to do?  A style sheet allows you to perform the following tasks:  Transform an XML document into another structure for the purpose of rendering it to a specific target. This may include:  Generating constant text, such as labels and headings  Specifying filters for extracting the required data  Changing the sequence of elements and attributes  Sorting the content  Performing complex transformations that compute values based on the existing content ©NIIT eXtensible Markup Language/Lesson 5/Slide 3 of 46
  • 4. Rendering XML Documents What does a Style Sheet Allow you to do? (Contd.)  Describe how to present the transformed information. Description of presentation includes:  Screen or page layout  Assignment of transformed content into lists and paragraphs  Specification of properties such as spacing, margins, alignment, and fonts ©NIIT eXtensible Markup Language/Lesson 5/Slide 4 of 46
  • 5. Rendering XML Documents Problem Statement 5.D.1 CyberShoppe wants to display the details of all the products that it sells. The product details need to be displayed in a browser in the format specified below:  The price per unit, description, and quantity on hand for each product should be displayed in teal color with a font size of 10 pts.  The name of the product must be displayed in red with a font size of 20 pts. It should be displayed in bold.  All details must be displayed in the Arial font. ©NIIT eXtensible Markup Language/Lesson 5/Slide 5 of 46
  • 6. Rendering XML Documents Task List Identify the elements to be displayed. Identify a mechanism to display formatted data. Create a style sheet to format data. Apply the style sheet to the XML document. View the document in a browser. ©NIIT eXtensible Markup Language/Lesson 5/Slide 6 of 46
  • 7. Rendering XML Documents Task 1:Identify the elements to be displayed. Result As per the given scenario, the elements that have to be displayed are:  PRODUCTNAME  PRICE  DESCRIPTION  QUANTITY ©NIIT eXtensible Markup Language/Lesson 5/Slide 7 of 46
  • 8. Rendering XML Documents Task 2:Identify a mechanism to display formatted data. Cascading Style Sheets (CSS)  A Cascading Style Sheet (CSS) is a type of style sheet that provides a simple mechanism for adding styles to an XML or HTML document.  A CSS is a text file containing one or more rules or definitions for the style characteristics of a particular element.  The CSS file can be included in a number of XML documents that have the same data structure. ©NIIT eXtensible Markup Language/Lesson 5/Slide 8 of 46
  • 9. Rendering XML Documents Task 2:Identify a mechanism to display formatted data. (Contd.) Result  As CSS allows you to format data in an XML document, CSS can be used to display the products data stored in the XML document in the specified format. ©NIIT eXtensible Markup Language/Lesson 5/Slide 9 of 46
  • 10. Rendering XML Documents Task 3:Create a style sheet to format data. CSS allows you to format the contents of a document by specifying the element name followed by the formatting instructions for that element. The syntax for coding a CSS is as follows: elementname { property1: value; property2: value; property3: value; } ©NIIT eXtensible Markup Language/Lesson 5/Slide 10 of 46
  • 11. Rendering XML Documents Task 3:Create a style sheet to format data. (Contd.) Action Type the code for creating the style sheet and save the file as product.css. ©NIIT eXtensible Markup Language/Lesson 5/Slide 11 of 46
  • 12. Rendering XML Documents Task 4:Apply the style sheet to the XML document. In order to apply the formatting specifications given in the CSS file to the data in an XML document, you need to associate the CSS with the XML document. This can be done using the following syntax: <?xml:stylesheet type="text/css" href="path-name"?> ©NIIT eXtensible Markup Language/Lesson 5/Slide 12 of 46
  • 13. Rendering XML Documents Task 5:View the document in a browser. ©NIIT eXtensible Markup Language/Lesson 5/Slide 13 of 46
  • 14. Rendering XML Documents Just a Minute… The details about all the books sold at CyberShoppe are to be displayed in the following format:  The book name is to be displayed in blue, Times New Roman, size 20pts, and bold.  The first name and last name of the author are to be displayed in green, Arial, and size 10pts.  Price of the book is to be displayed in red, Times New Roman, and size 20pts. Create a CSS for displaying the book details in the above format. ©NIIT eXtensible Markup Language/Lesson 5/Slide 14 of 46
  • 15. Rendering XML Documents Problem Statement 5.D.2 CyberShoppe needs to display product details, such as product ID, name of the product, and price per unit. In the output, all details about products should be displayed in red. ©NIIT eXtensible Markup Language/Lesson 5/Slide 15 of 46
  • 16. Rendering XML Documents Task List Identify the data to be displayed. Identify a mechanism for displaying selective data in a sorted order. Identify the elements required to display selective data in a sorted order. Create a style sheet. Apply the style sheet to the XML document. View the XML document. ©NIIT eXtensible Markup Language/Lesson 5/Slide 16 of 46
  • 17. Rendering XML Documents Task 1:Identify the data to be displayed. Result As per the given scenario, the data that is to be displayed is as follows:  PRODID  PRODUCTNAME  PRICE ©NIIT eXtensible Markup Language/Lesson 5/Slide 17 of 46
  • 18. Rendering XML Documents Task 2:Identify a mechanism for displaying selective data in a sorted order. CSS does not support operations, such as reordering and sorting elements based on a condition, and displaying only selective elements. To help you perform such operations, XML supports another style sheet language called eXtensible Style Sheet Language (XSL). XSL is made up of the following parts:  XSL Transformations (XSLT): It is an XML-based language that allows you to transform an XML document into another XML document. ©NIIT eXtensible Markup Language/Lesson 5/Slide 18 of 46
  • 19. Rendering XML Documents Task 2:Identify a mechanism for…(Contd.)  XML Path (XPath): It is a language that is used to access different parts of an XML document, such as elements and attributes. XSL uses XSLT to transform an XML document that contains data. XSLT contains instructions for specifying how an XML document is to be transformed. XSLT uses XPath expressions to extract specific data from an XML document. ©NIIT eXtensible Markup Language/Lesson 5/Slide 19 of 46
  • 20. Rendering XML Documents Task 2:Identify a mechanism for…(Contd.) A software called XSLT processor reads the instructions given in XSLT and transforms the XML document into another XML document, which uses formatting objects of XSL to display the XML document in the desired format. ©NIIT eXtensible Markup Language/Lesson 5/Slide 20 of 46
  • 21. Rendering XML Documents Task 2:Identify a mechanism for…(Contd.) Comparison between XSLT and CSS XSLT is a superset of the CSS functionality. XSLT is an application of XML. Therefore, it follows the XML syntax, whereas CSS has its own syntax. XML and CSS can co-exist since they meet different needs. XSLT is intended for complex formatting. ©NIIT eXtensible Markup Language/Lesson 5/Slide 21 of 46
  • 22. Rendering XML Documents Task 2:Identify a mechanism for…(Contd.) Working of the XSLT Processor MSXML Parser XSLT style sheet XSLT tree XSLT Result tree processo r XML document Source tree ©NIIT eXtensible Markup Language/Lesson 5/Slide 22 of 46
  • 23. Rendering XML Documents Task 2:Identify a mechanism for…(Contd.) Result Since XSL gives you added functionality of extracting specific data from an XML document, XSL can be used to select data as per the scenario. You need to use XSLT, which is a part of XSL, to create a style sheet. This style sheet should contain the instructions for transformation of an XML document into the result tree. ©NIIT eXtensible Markup Language/Lesson 5/Slide 23 of 46
  • 24. Rendering XML Documents Task 3:Identify the elements required to display selective data in a sorted order. XSLT provides a number of elements for selecting and formatting data. Some of the XSLT elements are:  stylesheet  value-of  for-each  sort  text ©NIIT eXtensible Markup Language/Lesson 5/Slide 24 of 46
  • 25. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The stylesheet element  Since an XSLT style sheet contains instructions for transforming XML documents, a declaration is added in the XSLT file to instruct the browser that it is a style sheet file. This declaration is known as style sheet declaration.  The syntax for style sheet declaration is as follows: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSLTransform" version=”1.0”> ©NIIT eXtensible Markup Language/Lesson 5/Slide 25 of 46
  • 26. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The value-of element  This element displays the value of the element or attribute specified. The syntax for using this element is as follows: <xsl:value-of select="elementname|attributename" />  If you want to display the value of an attribute, you must use the “@” symbol as a prefix with the attribute name. ©NIIT eXtensible Markup Language/Lesson 5/Slide 26 of 46
  • 27. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The for-each element  This element is used to instruct the XSLT processor to process the information for each instance of the specified pattern.  The syntax for using the for-each element is as follows: <xsl:for-each select="pattern"> [action to be performed] </xsl:for-each> ©NIIT eXtensible Markup Language/Lesson 5/Slide 27 of 46
  • 28. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The for-each element (Contd.)  The select attribute of the for-each element allows you to specify the elements or attributes on which the action needs to be performed.  The XSLT transformation instructions within the for-each element are applied to each of the nodes selected by the select attribute of the for- each element. ©NIIT eXtensible Markup Language/Lesson 5/Slide 28 of 46
  • 29. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The sort element  XSLT provides the sort element for sorting data based on values assigned to elements and attributes.  The sort element does not contain any child elements.  This element is always used as a child of the for- each element or the apply-templates element. ©NIIT eXtensible Markup Language/Lesson 5/Slide 29 of 46
  • 30. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The sort element (Contd.)  The syntax for using the sort element is as follows: <xsl:sort select="expression" order="ascending|descending" case-order="upper-first|lower-first“ data-type="text|number|qname"/> ©NIIT eXtensible Markup Language/Lesson 5/Slide 30 of 46
  • 31. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) The text element  The text element allows you to generate constant text in the output.  This element can be used to display labels. ©NIIT eXtensible Markup Language/Lesson 5/Slide 31 of 46
  • 32. Rendering XML Documents XSLT Template Rules XSLT allows you to define template rules for the output. A template rule describes how an XML element and its contents are converted into a format that can be displayed in the browser. A template rule consists of two parts:  A pattern that identifies an XML element in an XML document.  An action or processing code that details the transformation and rendering of the resulting element. ©NIIT eXtensible Markup Language/Lesson 5/Slide 32 of 46
  • 33. Rendering XML Documents XSLT Template Rules (Contd.) XSLT uses two main elements for creating template rules, template and apply-templates. The template Element  The template element is used to define a template for the desired output. The syntax for using this element is as follows: <xsl:template match="pattern"> [action to be taken] </xsl:template> ©NIIT eXtensible Markup Language/Lesson 5/Slide 33 of 46
  • 34. Rendering XML Documents XSLT Template Rules (Contd.) The apply-templates Element  This element is used to instruct the XSLT processor to find an appropriate template and perform the specified tasks on each selected element.  The syntax for using this element is as follows: <xsl:apply-templates [select="pattern"]>  The select attribute is optional and is used to specify the context in which the template should be executed. ©NIIT eXtensible Markup Language/Lesson 5/Slide 34 of 46
  • 35. Rendering XML Documents XSLT Template Rules (Contd.) The apply-templates Element (Contd.)  You can effectively use templates in order to display data.  The XSLT processor always starts processing from the root element. Therefore, it starts processing from the template rule <xsl:template match=“/”>.  If you have more than one template rule created for the same element, the previous template rule will be overridden by the other template. ©NIIT eXtensible Markup Language/Lesson 5/Slide 35 of 46
  • 36. Rendering XML Documents XSLT Template Rules (Contd.) ©NIIT eXtensible Markup Language/Lesson 5/Slide 36 of 46
  • 37. Rendering XML Documents XSLT Template Rules (Contd.) Default Template To prevent the processing of templates from stalling when there is no suitable selection rule, the XSLT processor assumes a default template rule. ©NIIT eXtensible Markup Language/Lesson 5/Slide 37 of 46
  • 38. Rendering XML Documents XSLT Template Rules (Contd.) Default Template (Contd.)  The default template rule consists of the following statements: <xsl:template match= "/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="*"> <xsl:apply-templates /> </xsl:template> <xsl:template match="text()"> <xsl:value-of select="."> </xsl:template> ©NIIT eXtensible Markup Language/Lesson 5/Slide 38 of 46
  • 39. Rendering XML Documents Task 3:Identify the…sorted order. (Contd.) Result The following XSLT elements are used to extract and format the required data:  stylesheet: To specify the style sheet declaration.  for-each: To display the product ID, product name, and price for each instance of the product element.  value-of: To display the values of PRODID, PRODUCTNAME, and PRICE.  sort: To sort the elements and attributes containing product details based on the product ID.  text: To display the labels for various elements and attributes.  template: To be used as the parent element of the for- each element. ©NIIT eXtensible Markup Language/Lesson 5/Slide 39 of 46
  • 40. Rendering XML Documents Task 4:Create a style sheet. Action As per the scenario, the product details, such as PRODUCTID, PRODUCTNAME, and PRICE have to be sorted in the ascending order of the PRODID attribute. To do this, type the necessary code as save the file as product1.xsl. ©NIIT eXtensible Markup Language/Lesson 5/Slide 40 of 46
  • 41. Rendering XML Documents Task 5:Apply the style sheet to the XML document. To view selective details of a product, such as product ID, name, and rate from an XML document, you need to associate the XML document with the XSL file that renders the required data. This can be done using the following syntax: <?xml:stylesheet type="text/xsl" href="path-name"?> Action Type the code for creating the XML document as save the file as product.xml. ©NIIT eXtensible Markup Language/Lesson 5/Slide 41 of 46
  • 42. Rendering XML Documents Task 6:View the XML document. ©NIIT eXtensible Markup Language/Lesson 5/Slide 42 of 46
  • 43. Rendering XML Documents Problem Statement 5.P.1 CyberShoppe wants to display the details of all books to its customers. The book details that have to be displayed are book ID, title, and rate of books. The book details must be displayed in the ascending order of rate and book ID. ©NIIT eXtensible Markup Language/Lesson 5/Slide 43 of 46
  • 44. Rendering XML Documents Summary In this lesson you learned that: Rendering is the process of presenting the data in an XML document in different formats. A style sheet is a separate document that contains the formatting rules for one or several XML documents. There are two types of style sheets used with XML documents. They are:  Cascading Style Sheets (CSS)  eXtensible Stylesheet Language (XSL) ©NIIT eXtensible Markup Language/Lesson 5/Slide 44 of 46
  • 45. Rendering XML Documents Summary (Contd.) CSS is used to define the style or appearance of an XML document. XSL is made up of XSL Transformations (XSLT) and XML Path (XPath). XSLT is a superset of the CSS functionality. XSLT is used to display selective elements or attributes, sort data on one or more elements, and process the data on the basis of a condition. XSLT elements, such as template, apply- templates, sort, for-each, and value-of are used to extract and format data. ©NIIT eXtensible Markup Language/Lesson 5/Slide 45 of 46
  • 46. Rendering XML Documents Summary (Contd.) An XSLT style sheet contains a set of templates rules. A template rule describes how an XML element and its contents are converted into a format that can be displayed in the browser. Each template rule has two parts: a pattern and an action. The reference to a style sheet file is included in an XML document by using the syntax <?xml:stylsheet type="text/css or xsl" href="path- name"?> ©NIIT eXtensible Markup Language/Lesson 5/Slide 46 of 46