Class 9 Notes for XML


Learning Objectives:

You will be able to create an XSL document for an XML document

You will be attach an XSL document to an XML document.

Homework:

Read the XSL tutorials from the W3schools.

Read: Chapter 6

XSL Definition:

XSL is an XML document!

XSL is the marriage between HTML and XML to create a document that is viewable by us mere mortals.

XSL is a language that can transform, filter and sort XML data into HTML or prepare the data for different devices, like screen, paper or voice.

A common way to describe the transformation process is to say that XSL uses XSLT to transform an XML source tree (starting document) into an XML result tree (the finished product)

How does it work?

In the transformation process, XSL uses XPath to define parts of the source document that match one or more predefined templates.

When a match is found, XSL will transform the matching part of the source document into the result document. The parts of the source document that do not match a template will (as a general rule) end up unmodified in theresult.

Source Tree (XML Document Before Transformation) ------> Result Tree (After Transformation)

Syntax for calling an XSL document from an XML:

<?xml-stylesheet type="text/xsl" href="URL-of-XSL-document"?>

Add XSL to your  XML Resume & XML Address book documents

Topics Covered:

Practice Xpath:

What is the path to ingredient, currency, product_code & name for this XML Document

 

XSL Definition:

XSL is an XML document!

XSL is the marriage between HTML and XML to create a document that is viewable by us mere mortals.

XSL is a language that can transform, filter and sort XML data into HTML or prepare the data for different devices, like screen, paper or voice.

A common way to describe the transformation process is to say that XSL uses XSLT to transform an XML source tree (starting document) into an XML result tree (the finished product)

How does it work?

In the transformation process, XSL uses XPath to define parts of the source document that match one or more predefined templates.

When a match is found, XSL will transform the matching part of the source document into the result document. The parts of the source document that do not match a template will (as a general rule) end up unmodified in theresult.

Source Tree (XML Document Before Transformation) ------> Result Tree (After Transformation)

 

Syntax for calling an XSL document from an XML:

<?xml-stylesheet type="text/xsl" href="URL-of-XSL-document"?>

Example of XSL Document Syntax

<?xml version="1.0"?>
< xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

< xsl:template match="/">

Formating of XSL document (Template)

</xsl:template>


< /xsl:stylesheet>

Template creation:

The first step I used was to identify the information I wanted and construct a path

<xsl:for-each select="FallSchedule/Class">

to that information. The xsl:for-each creates a loop that continues until you end the XML document.

The second step was creating a formula to display the information I wanted

<xsl:value-of select="Number" />

I wanted to display only the information contained by the Number element!

The final step was to add HTML tags to the XSL to display (render) the information I selected.

 

Template Manipulations:

Element Name Description Attributes
xsl:apply-templates Applies a template to the current element. order-by="+|-pattern"
select="pattern"
xsl:attribute Adds a new attribute to the current output element. name="attribute-name"
xsl:cdata Adds a new CDATA section to the output.
xsl:choose Provides a selection mechanism based on conditions.
xsl:comment Adds a comment node to the output.
xsl:copy Copies the current node to the output.
xsl:define-template-set Defines a new set of templates
xsl:element Adds a new element node to the output. name="name"
xsl:entity-ref Adds a new entity reference node to the output. name="name"
xsl:eval Provides an evaluation mechanism to evaluate output content. language="language"
xsl:for-each Provides a mechanism to create a loop in the output stream. select="pattern"
order-by="-|+ pattern"
xsl:if Provides a conditional branch mechanism based on a condition. match="pattern"
xsl:node-name Adds the name of the current node to the output.
xsl:otherwise Part of the choose mechanism (see xsl:choose).
xsl:pi Adds a processing instruction to the output. name="name"
xsl:script Defines a script area inside a template. language="language"
xsl:stylesheet Defines the root element of the style sheet. xmlns:xml="namespace"
language="language"
indent-result="yes|no"
xsl:template Defines a template. match="pattern"
language="language"
xsl:value-of Defines a node to insert into the output. select="pattern"
xsl:when Part of the choose mechanism (see xsl:choose) test="expression"

 

Practice:

I want to take by XML version of my fall schedule and display only the class number. I can use an XSL template to display only the information I want!

Terms:

Xpath, XSL, XSL template, Source Tree, Result Tree

 

 

 

Dr. Jon Storslee
Phone: 602-787-6734

HTML Valid


Paradise Valley Community CollegeĀ 
18401 N. 32nd Street Phoenix, AZ 85032