Presentation is loading. Please wait.

Presentation is loading. Please wait.

CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "http://www.w3.org/1999/XSL/Transform"

Similar presentations


Presentation on theme: "CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "http://www.w3.org/1999/XSL/Transform""— Presentation transcript:

1 CITA 330 Section 6 XSLT

2 Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "http://www.w3.org/1999/XSL/Transform" Its root element is stylesheet or transform Example XSLT stylesheet: DVD Library Listing

3 Transforming XML Documents to XHTML Documents Title Format Genre

4 Transforming XML Documents to XHTML Documents The root element stylesheet declares a namespace prefix "xsl" for XSL namespace "http://www.w3.org/1999/XSL/Transform" The 2nd line’s xsl:output element specifies that the output file of this transformation should follow the specification of HTML v 4.0 Each xsl:template element specifies a transformation rule: if the document contains nodes satisfying the XPath expression specified by the xsl:template’s match attribute, then they should be transformed based on the value of this xsl:template element Since this particular match attribute has value "/" selecting the root element of the input XML document, the rule applies to the entire XML document

5 Transforming XML Documents to XHTML Documents The XSLT template uses an xsl:for-each element to loop through the dvd elements selected by the xsl:for-each element’s select attribute In the loop body, the selected dvd elements are first sorted based on their genre value Then the xsl:value-of elements are used to retrieve the values of the elements selected by their select attributes To use a web browser to transform the earlier file library.xml with this XSLT file library.xsl into HTML, you can add the following line after the XML declaration:

6 Transforming XML Documents to XHTML Documents The resulting Web browser presentation

7 XSLT An XSLT style sheet contains instructions for transforming the contents of an XML document into another format An XSLT style sheet document is itself an XML document An XSLT style sheet document has an extension.xsl

8 XSLT An XSLT style sheet converts a source document of XML content into a result document by using the XSLT processor

9 XSLT The transformation can be performed by a server or a client In a server-side transformation, the server receives a request from a client, applies the style sheet to the source document, and returns the result document to the client In a client-side transformation, a client requests retrieval of both the source document and the style sheet from the server, then performs the transformation, and generates the result document

10 XSLT To create an XSLT style sheet, the general structure is: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> Content of the style sheet The tag can be substituted for the tag

11 Root Template A template is a collection of elements that define how a particular section of the source document should be transformed in the result document The root template sets up the initial code for the result document

12 Template To create a template, the syntax is: styles – where node set is an XPath expression that references a node set from the source document and styles are the XSLT styles applied to those nodes

13 To create a root template, the syntax is: styles Root Template

14 A template contains two types of content: XSLT elements and literal result elements –XSLT elements are those elements that are part of the XSLT namespace and are used to send commands to the XSLT processor –A literal result element is text sent to the result document, but not acted upon by the XSLT processor Template

15 Output Method By default, the XSLT processor will render the result document as an XML file To control how the processor formats the source document, you can specify the output method using the element

16 xsl:output Attributes

17 Transforming a Document A browser with a built-in XSLT processor allows you to view the result document Alternatively, you can use XML tools (such as XML Spy) to create the result document as a separate file, and then view that file in your browser Most XSLT processors provide the capability to create the result document as a separate file

18 Extracting Element Values To insert a node’s value into the result document, the syntax is: – –where expression is an expression that identifies the node from the source document’s node tree If the node contains child elements in addition to text content, the text in those child nodes appears as well

19 Processing Several Elements To process a batch of nodes, the syntax is: styles where expression is an expression that defines the group of nodes to which the XSLT and literal result elements are applied

20 Working with Templates To apply a template in the result document, use the XSLT element where expression indicates the node template to be applied

21 Sorting Node Sets By default, nodes are processed in document order, by their appearance in the document To specify a different order, XSLT provides the element This element can be used with either the or the element

22 The element contains several attributes to control how the XSLT process sorts the nodes in the source document –The select attribute determines the criteria under which the context node is sorted –The data-type attribute indicates the type of data –The order attribute indicates the direction of the sorting (ascending or descending) Sorting Node Sets

23 Conditional Nodes XSLT supports two kinds of conditional elements: – To apply a format only if a particular condition is met, use the element To test for multiple conditions and display different outcomes, use the element


Download ppt "CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "http://www.w3.org/1999/XSL/Transform""

Similar presentations


Ads by Google