XSLT Introduction
What is XSLT?
— XSLT is a short term for Extendable Stylesheet Language
Transformation.
DEFINITION:
= Adeclarative programming language for specifying
transformations between XML languages
— Even though it is a "stylesheet," it has a different goal than
CSS (Cascading Stylesheets). XSLT is not used for visual effect,
but instead extracting data (or transforming) from XML and
using the combination of HTML and CSS to format them.
— XSLT also has the dynamic properties where you can do
iteration and conditional statements upon a static XML file.USES OF XSLT
XML documents are self describing and structured documents,
To generate the XML file as HTML file to be displayed by a browser.
XSLT can be used for organizing large trees of XML so that anyone
can read it
To generate new XML documents from existing XML documents.
Designed primarily for XML-to-XML and XML-to-HTML
transformations.
XSLT also cuts down on server load. Since XSLT can do the
transformation on the client site, the server has to do less work,
since we are not querying upon data in database.Why XSLT?
Simple syntax
Easy to write
Easy to read and understand
Reusable
~All the advantages of being the XML based
language~ XSLT uses XPath to find information in an XML
document.
“In the transformation process, XSLT uses XPath to
define parts of the source document that should
match one or more predefined templates.
“When a match is found, XSLT will transform the
matching part of the source document into the
result document. bh~ XSL uses XSLT which uses Xpath.
- The style sheet describes rules for transforming a source tree into a
result tree.
- When a pattern is matched in the source tree, the corresponding
pattern is generated in the result tree.
= XSUT processor reads both an XML document and an XSLT style sheet, and it
outputs a new XML document or fragment.
To get access to the XSLT Slements, attributes and features we
must declare the XSLT namespace at the top of the document.
- _ xmins:xsl="http://www.w3.org/1999/XSL/Transform" points to
the official W3C XSLT namespace.
- To use this namespace, we must also include the attribute
version="1.0".
xmins:xsl:
+ XSLT uses two input files:
— The XML document containing the actual data,
= The XSL document containing both the “framework” in which to
insert the data, and XSLT commands to do so.
[action]
">
+ File data.xml:
Welcome to this Course! le
+ File render.xst:
‘An XSLT document has the .xsl extension
The XSLT document begins with:
XML declaration
Every XSLT file must have a root element,
Contains one or more templates, such as:
...
And ends with:
+ The template says to select the
— selecting the root node of the XML tree
+ Inside this template,
— selects the
message child R
= Alternative Xpath expressions that would also work:
+ ./message
+ /message/text() (text() is an XPath function)
+ /message/text()Matching and Selecting Templates
* xsl:template
© xsl:apply-template
* xsi:value-of
h
Branching Elements
¢ xsl:for-each
© xshif
* xsl:chooseXSLT
An XSL style sheet consists of one or more set of rules that are
called templates.
A template contains rules to apply when a specified node is
matched.
The element is used to build templates.
The match attribute is used to associate a template with an
XML element or it specifies the pattern.
The match attribute can also be used to define a template for
the entire XML document
The value of the match attribute is an XPath expression (i.e.
match="/" defines the whole document)
required unless the xsl:template element has a name attributeXSLT TEMPLATE ATTRIBUTE DECLARATION.
DECLARATION
ty
Frame [Desrotion
name Name of the element on which template is to be applied.
Pattern which signifies the element(s) on which template is to be
match
applied.
riorit Priority number of a template. Matching template with low priority is
Priority not considered in from in front of high priority template,
mode Allows element to be processed multiple times to produce a different
result each time.STUDENT.XML
Diwakar
Vijay
GoneSTUDENT.XSL
| Roll No |
First Name |
STUDENT.XSL
| |
|