PART-1 Introduction To XSLT (Extensible Style Language For: Transformation)
PART-1 Introduction To XSLT (Extensible Style Language For: Transformation)
PART-1 Introduction To XSLT (Extensible Style Language For: Transformation)
INTRODUCTION TO XSLT
(Extensible Style Language for
Transformation)
source
source document
document
source tree
XSL
XSL stylesheet
stylesheet XML
XML parser
parser
apply
apply
write
write result
result templates
templates
to output
to output
result tree
rule
• XML elements
ATTRIBUT para
para para
para para
para
Attribute nodes
• XML attributes
E
note
note warning
warning warning
warning
Text nodes
content
content content
content content
content
• Textual content in XML elements
Comment nodes
• XML comments TEXT
Processing instruction nodes
• XML processing instructions
Namespace nodes
• The in-scope namespaces on an element
note
note warning
warning warning
warning
content
content content
content content
content
- ro o t-
d ocum ent
- e le m e n t- - e le m e n t- - e le m e n t-
p a ra p a ra p a ra
- a ttr ib u te - - te x t- - a t tr ib u t e - - te x t- - a t tr ib u t e - - te x t-
ty p e : n o te c o n te n t t y p e : w a r n in g c o n te n t t y p e : w a r n in g c o n te n t
NODE TEST
AXIS
• select the second para child of the context node that has a type
attribute with a value of warning.
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
d o cu m e nt
p a ra p a ra p a ra
Axis
ty p e :n o te ty p e :w a r n in g ty p e :w a r n in g
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
d o cu m e nt
Filtered
p a ra p a ra p a ra
Axis
ty p e :n o te t y p e :w a r n in g ty p e :w a r n in g
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
d o cu m e nt
Filtered
p a ra p a ra p a ra
Axis
ty p e :n o te t y p e :w a r n in g ty p e :w a r n in g
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
d o cu m e nt
Filtered
p a ra p a ra p a ra
Axis
ty p e :n o te t y p e :w a r n in g ty p e :w a r n in g Selected
12/7/21 Name of the presentation Page | 18
Types of XPaths
Expressions:
Return a value, which might be a node set that is processed or a string
that is output.
<xsl:when test="@type=‘warning’">
Patterns:
Either match a particular node or don't match that node.
<xsl:template match="para">
Conditional Z Z
<xsl:if test=“position()=2”>
C
Calculation 1 2 3 4
<xsl:value-of select=“position()+4">
<xsl:for-each select=“child::para”>
<xsl:apply-templates select="paragraph"/>
<xsl:for-each select=“/R/N”> R
<xsl:for-each select=“N”> N Z
note: same as “child::N”
11
22
11
11 22
11 33
22 44 55 66
11
22 44
33 55 66 77
11 44
22 33
11 22
11
33
22 11
22 11
11
This XPath
expression selects all
the price elements of
all the cd elements of
the catalog element:
/catalog/cd/price
This XPath
expression selects
all the cd elements
in the document:
//cd
*note most XPath expressions are written in shorthand
• The following XPath expression selects all the price elements that are
grandchild elements of the catalog element:
/catalog/*/price
• The following XPath expression selects all price elements which have 2
ancestors:
/*/*/price
• The following XPath expression selects the last cd child element of the
catalog element (Note: There is no function named first()):
/catalog/cd[last()]
• The following XPath expression selects all the title, artist and price
elements in the document:
//title | //artist | //price