• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rendering XML Documents
 

Rendering XML Documents

on

  • 3,332 views

Rendering XML Documents

Rendering XML Documents

Statistics

Views

Total Views
3,332
Views on SlideShare
3,330
Embed Views
2

Actions

Likes
1
Downloads
113
Comments
0

1 Embed 2

http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Rendering XML Documents Rendering XML Documents Presentation Transcript

  • Rendering XML Documents XML http://yht4ever.blogspot.com [email_address] B070066 - NIIT Quang Trung 08/2007
  • Contents Formatting Data using XSLT Introducing XSL Introducing CSS Define rendering
  • Define rendering
    • Rendering refers to processing an XML document to present it with the desired formatting.
    • XML does not focus on formatting. Therefore, a style sheet is required for formatting and rendering XML documents.
    • A style sheet performs the following tasks:
      • Transform an XML document into another structure and render it to a specific target.
      • Describe how to present the transformed information.
    • Style sheets can be of the following three types:
      • Cascading Style Sheets
      • eXtensible Style Sheets
      • Document Style Semantics and Specification Language (DSSSL)
  • Introducing CSS
    • Creating CSS
      • The syntax for coding a CSS is:
      • elementname {
      • property1: value;
      • property2: value;
      • }
      • In the preceding syntax:
        • elementname specifies the name of the element.
        • property1 and property2 specify the property names.
        • Value specifies the property values for a property name.
  • Introducing CSS (cont.)
    • Applying CSS
      • The CSS file needs to be associated with the XML document for applying formatting specifications.
      • A CSS can be applied to an XML document using the Processing Instruction:
      • <?xml:stylesheet type=&quot;text/css&quot; href=&quot;path-name&quot;?>
      • In the above statement:
        • xml:stylesheet instructs the browser that the XML document uses a stylesheet.
        • type specifies the type of formatting used.
        • href specifies the name of the CSS file used to format the XML document.
  • Demo & Exercises
    • Ex1:
      • The employee information is stored in the emp.xml file. Use this file to display the employee details in the following format:
        • Name of the employee: Times New Roman, blue, 20pts
        • Designation: Arial, green, 10pts
        • Department: Arial, green, 10pts
        • Salary: Times New Roman, blue, 20pts
    • Use cascading style sheets to format the data in the emp.xml file.
  • Introducing XSL
    • CSS does not support the reorder, sort, and display of elements based on a condition.
    • For such advanced formatting, XML supports e X tensible S tylesheet L anguage (XSL).
    • XSL has two parts:
      • XSL Transformations (XSLT)
      • XML Path (XPath)
    • XSL:
      • Contains instructions on how an XML document should be transformed into an HTML or XHTML document.
      • Uses XPath expressions to extract specific data from an XML document.
    • The XSLT processor transforms the XML document into an HTML or XHTML or into another XML document.
  • Introducing XSL (cont.)
    • Comparing CSS and XSLT
      • The following table draws a comparison between CSS and XSLT:
    Follows the XML syntax. Does not use XML syntax. Uses more memory and processor power. Uses less memory. Allows access and manipulation of the comments, PI, and attribute values and names within an XML document. Does not offer access to non-elements, such as attributes, attribute values, and PI. Can reorder, add, or delete elements. Cannot reorder, add, delete, or perform operations on elements. Complex to use. Simple to use, and suitable for simple documents. XSLT CSS
  • Introducing XSL (cont.)
    • Analyzing the Working of the XSLT Processor
      • The XSLT processor applies the transformation information to the source document and builds the result tree as shown in the following figure:
  • Formatting Data using XSLT
    • Formatting Data using XSLT
      • XSLT provides the following elements to select and format data:
        • stylesheet
        • value-of
        • for-each
        • sort
        • text
      • The stylesheet element:
        • Instructs the browser that the document is a style sheet file.
        • Is the root element for all XSLT style sheets.
        • Is written as:
        • <xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;>
  • Formatting Data using XSLT (cont.)
    • Formatting Data using XSLT (cont.)
      • The value-of element:
        • Displays the value of the specified element or attribute.
        • Follows the syntax:
        • <xsl:value‑of select=&quot;elementname/attributename&quot;/>
      • The for-each element:
        • Instructs the XSLT processor to process the information for each instance of the specified pattern.
        • Follows the syntax:
        • <xsl:for-each select=&quot;pattern&quot;>
        • [action to be performed]
        • </xsl:for-each>
  • Formatting Data using XSLT (cont.)
    • Formatting Data using XSLT (cont.)
      • The sort element:
        • Sorts data based on the values assigned to elements and attributes.
        • Follows the syntax:
        • <xsl:sort select=&quot;expression&quot; order=&quot;ascending|descending&quot; case-order=&quot;upper-first|lower-first“
        • data-type=&quot;text|number|qname&quot;/>
      • The text element:
        • Generates constant text in the output and displays labels.
        • Follows the syntax:
        • <xsl:text> Text to be displayed as label </xsl:text>
  • Formatting Data using XSLT (cont.)
    • Creating XSLT Template Rules
      • A template rule:
        • Describes how an XML element and its contents are converted into a specific format for displaying in the browser.
        • Consists of two parts, pattern and action.
      • The template element:
        • Defines a template for the desired output
        • Follows the syntax:
    • <xsl:template match=&quot;pattern&quot;>
    • [action to be taken]
    • </xsl:template>
  • Formatting Data using XSLT (cont.)
    • Creating XSLT Template Rules (cont.)
      • The apply-template element:
        • Instructs the XSLT processor to find an appropriate template and perform the specified tasks on selected elements.
        • Follows the syntax:
        • <xsl:apply‑templates [select=&quot;pattern&quot;]>
  • Formatting Data using XSLT (cont.)
  • Demo & Exercises
    • To be continued…
  • Reference
    • XML How to program
    • http://www.w3.org
    • Teach Yourself XML in 21 Days, 3 rd Edition
    • Learning XML, 2 nd Edition
    • Andy Clark presentation.
    • XML tutorial http://www.w3schools.com/w3c/
  • Q&A
    • Feel free to post questions at http://yht4ever.blogspot.com
    • or email to: [email_address] or [email_address]
  • http://yht4ever.blogspot.com Thank You !