XSLT(EXtensible Style Sheet Language)
Transcript of XSLT(EXtensible Style Sheet Language)
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
1/35
XSLT(EXTENSIBLE STYLESHEET
LANGUAGE)
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
2/35
WHAT IS XSLT
From a programmers view
It is a programming language for
processing XML data i.e transforming XML
documents based on the requirment.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
3/35
WHY WOULD YOU NEED XSLT
In the dynamic world we would need convert therequired input file to the required file .
This is easy to learn as it is based on xml only.
Gives us very versatile list of option for theconversion.
Building block for xml based technologies.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
4/35
HIGH LEVELVIEW OF WHAT IS XSLT
DOING
Input is a XML
XSLT Processor
Can produce another xml
Xslt file needed for
processing
Can produce a
html/xhtmlhttps://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
5/35
REQUIRMENT(SAXON PROCESSOR)
Please download the Tool from
http://saxon.sourceforge.net/
Please download the latest version for this.
https://www.focustread.com/training
http://saxon.sourceforge.net/http://saxon.sourceforge.net/ -
8/3/2019 XSLT(EXtensible Style Sheet Language)
6/35
WHAT IS XSLT PROCESSOR
In order to convert the xml into the required the
xml or html , a XSLT processor is needed .
This processor takes into input the .xslt file andbased on the declaration done in the .xslt file the
required output is generated.
SYNTAX
Java jar saxon.jar
< resultfile.xml/html>https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
7/35
ASIMPLE EXAMPLE
people.xml
Andy
he is Java teacher
Candy
She is oracle teacher
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
8/35
FIRST.XSLT
Information about people
Information about
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
9/35
ELEMENT
This is the first element of the xslt which defines
the version and Namespace of the xslt.
example
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
10/35
ELEMENT
The xslt processor looks for the template tag
with the match open as /
when xslt processor find a node of this type it
then then start creating the result xml/html.
Example
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
11/35
ELEMENT
This element provides the values from the source
xml , based on the condition provided in it .
It has a mandatory attribute select , which is
used to provide the condition to based on which
respective values from the source xml are
selected.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
12/35
ELEMENT
This element copies the a node to the result tree
, but it doesnt copy any descendant nodes .
If the context node is a element then it doesnt
copy any of it attribute.
This is useful you want to change the structureof the element i.e add or remove its attributes .
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
13/35
EXAMPLE
Andy
Jackson
Candy
Soni
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
14/35
CONVERTCOPY.XSLT
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
15/35
CONVERT IT BACK
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
16/35
RESULT.XML
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
17/35
ELEMENT
It does the deep copy .
It copies ( a node,its attribute and its
descendants) all of them to the resultant tree.
Example
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
18/35
EXAMPLE
(PURCHASEORDER TO INVOICE)
PurchaseOrder.xml
USA
India
234 Any Street
My City
1122334
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
19/35
(PURCHASEORDER TO INVOICE)
Invoice.xml
USA
India
234 Any Street
My City
1122334
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
20/35
(PURCHASEORDER TO INVOICE)
PurchaseOrder.xslt
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
21/35
ELEMENT
This element is being used to call out which type
of output we need as the result.
Syntax for xml output
Syntax for html output
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
22/35
CONDITIONAL PROCESSING
In Xslt you have following option for conditional
processing
1.
.
2.
3.
4.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
23/35
ELEMENT
It tests xsl:if element for boolean result .
If the result is true then content of xsl:if areinstantiated and added to the result tree.
If the result id fale the nothing is being added.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
24/35
EXAMPLE
xslifExample.xml
First Person
First PersonFirst Person
First Person
First Person
First Person
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
25/35
EXAMPLE
xslifExample.xslt
This is for the Test
The Record of the age is very high
The age of is
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
26/35
ELEMENT
This works almost like if then-else statment .
This is useful if you want your code to take somedecision based on the tested condition is true or false.
Example
code to display when condition is true.
Code will come here when the condition is false
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
27/35
EXAMPLE
xslchooseExample.xml
First Person
First PersonFirst Person
First Person
First Person
First Person
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
28/35
EXAMPLE xslchooseExample.xslt
This is for the Test
The Record of the age is very high
The age of is is very high
The age of is is very okay
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
29/35
It is being used to process all the nodes in the in
the node-set according to the XSLT instructions
nested inside the xsl:for-each element.
Syntax
Code which is to be processed.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
30/35
EXAMPLE
xslforeachExample.xml
Hard
Shiny4 wheels
2 people capacity
SoftOrange
Sweet
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
31/35
EXAMPLE
xslforeachExample.xslt
This is for-Each Test
This is for-Each Test
Shows the result of
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
32/35
ELEMENT
This is used to specify the sort order of the node-
sets .
This can work with
a. xsl:template-apply element.
b. xsl:for-each element.
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
33/35
EXAMPLE
xslsort.xml
Hard
Shiny4 wheels
2 people capacity
SoftOrange
Sweet
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
34/35
EXAMPLE xslsort.xslt
This is Sort Test
This is Sort Test
Shows the result of
https://www.focustread.com/training
-
8/3/2019 XSLT(EXtensible Style Sheet Language)
35/35
AND
They are mentioned by below mentioned syntax
They act like constants and there value cannot
change once they are set.
https://www.focustread.com/training