• Introduction
• uPortal
• Basic XPath
• Basic XSLT
• Markup: XHTML
• Cascading Style Sheets
• Tools
• The Creation Process
• Hands-on
Introduction
XSLT, XPath and uPortal Background
• Who: W3C
• What: XPath and XSLT Specs.
• When: 11/16/1999
• Why: A need arose for a
specification to define the
syntax and semantics for
transforming XML
documents.
XSLT, XPath and uPortal References
• “The” definitive
reference…
• Michael Kay
• Wrox Press Inc
• ISBN: 1861005067
XSLT, XPath and uPortal References
• Great practical
reference…
• Jeni Tennison
• Hungry Minds
• ISBN: 0764547763
XSLT, XPath and uPortal References
• Practical use of
transformations
in Java code
• Eric Burke
• O'Reilly & Assoc.
• ISBN: 0596001436
JA-SIG’s uPortal
XSLT, XPath and uPortal What’s new in 2.0?
• Abstraction of layout
• Structure/theme transformations
• Standard channel events
• Standard CSS classes
• More flexible publish/subscribe
• User profile management
• JNDI lookup service
• WebProxy channel
XSLT, XPath and uPortal Basic Architecture
XSLT, XPath and uPortal Basic Architecture
Permissions
iPlanet
authentication LDAP
User preferences
Channel registry
IChannel
uPortal Framework
User Layout
Channel
XSLT, XPath and uPortal Structure Transformation
User Layout
Channel
User Layout
XSLT
structuredLayout
setRuntimeData()
XSLT
Channels Theme
renderXML()
transformation
XML
XSLT
Processor
HTML: PDA
Stylesheet
• Structures
• Tab / column
• Tree / column
• Themes
• Multi-column
• Multi-row
• Skins
• Matrix, Java
XSLT, XPath and uPortal Multiple Target Devices
XSLT, XPath and uPortal Tab / Column Layout
XSLT, XPath and uPortal Tree / Column Layout
XSLT, XPath and uPortal Theme: java
XSLT, XPath and uPortal Theme: imm
XSLT, XPath and uPortal Theme: matrix
XSLT, XPath and uPortal User preferences
• Portal=rendering+customization
• User Preferences Channel
• Swappable layout and preference
management modules
• Profile management module
• Tab-column specific UP module
• Skin Selection
XSLT, XPath and uPortal User Preferences
XSLT, XPath and uPortal Publish/Subscribe
<document>
<para type=“note”> content </para>
<para type=“warning”> content </para>
<para type=“warning”> content </para>
</document> document
document
para
para para
para para
para
note
note warning
warning warning
warning
content
content content
content content
content
-root-
document
child::para[attribute::type='warning'][position()=2]
• In English:
• select the second para child of the
context node that has a type attribute
with a value of warning.
XSLT, XPath and uPortal Dissecting the Example
child::para[attribute::type='warning'][position()=2]
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
document
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
document
Filtered
XSLT, XPath and uPortal Dissecting the Example
child::para[attribute::type='warning'][position()=2]
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
document
Filtered Filtered
XSLT, XPath and uPortal Dissecting the Example
child::para[attribute::type='warning'][position()=2]
Axis: child::para
Filter: [attribute::type='warning']
Filter: [position()=2]
Context node
document
• 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">
XSLT, XPath and uPortal XPath Expressions
• Select Nodes C
<xsl:for-each select=“child::Z”>
Z Z
• Conditional C
<xsl:if test=“position()=2”>
1 2 3 4
• Calculation
<xsl:value-of select=“position()+4">
XSLT, XPath and uPortal Node Set Expressions
<xsl:for-each select=“child::para”>
<xsl:apply-templates select="paragraph"/>
XSLT, XPath and uPortal Location Paths
<xsl:for-each select=“/R/N”> N X Y N
R
• Relative location paths
start from the context node.
• ancestor :: node()
Takes you up the tree to the ancestors of
the context node in reverse document
order.
1
XSLT, XPath and uPortal Axes
• ancestor-or-self :: node()
Takes you up the tree to the ancestors of
the context node in reverse document
order starting with the context node.
1
XSLT, XPath and uPortal Axes
• child :: node()
Takes you to the children of the context
node in document order. This is the
default axis.
1 2
XSLT, XPath and uPortal Axes
• descendant :: node()
Takes you to the descendants of the
context node. The resulting nodes are in
document order.
1 3
2 4 5 6
XSLT, XPath and uPortal Axes
• descendant-or-self :: node()
Takes you to the descendants of the
context node, starting with the context
node, in document order.
2 4
3 5 6 7
XSLT, XPath and uPortal Axes
• following :: node()
Takes you to the nodes that occur after
the context node in document order, but
that are not the context node’s
descendants.
1 4
2 3
XSLT, XPath and uPortal Axes
• following-sibling :: node()
Takes you to the siblings of the context
node that occur after the context node in
document order.
1 2
XSLT, XPath and uPortal Axes
• parent :: node()
Selects a single node – the parent of the
context node.
1
XSLT, XPath and uPortal Axes
• preceding :: node()
Takes you to the nodes that occur before
the context node in reverse document
order, excluding the context node’s
ancestors.
2 1
XSLT, XPath and uPortal Axes
• preceding-sibling :: node()
Takes you to the siblings (children of the
same parent) of the context node that
occur before it, in reverse document
order.
2 1
XSLT, XPath and uPortal Axes
• self :: node()
Takes you to the context node itself.
1
XSLT, XPath and uPortal Predicates (filters)
• Logical Operators
• and, or and not()
• Comparative Operators
• =, !=, <, <=, >, >=
• Remember to escape: “<“ to <
• Mathematical Operators
• +, -, *, div, mod
XSLT, XPath and uPortal XPath Examples
select=“presidents/president/[position()=3]/name”
select=“//president[count(vicePresident)=0]/name”
select=“descendant::president/
[count(vicePresident)>1]/name”
select=“//president/name[child::first=‘John’]”
source
source document
document
source tree
XML
XML parser
parser
XSL
XSL stylesheet
stylesheet
rules base
apply
apply
Result
Result file
file write
write result
result templates
templates
or stream
or stream to output
to output
result tree
XSLT, XPath and uPortal Differentiating Stylesheets
• <xsl:decimal-format>
• Declares a decimal format.
• <xsl:import>
• Imports another stylesheet into this stylesheet.
• <xsl:key>
• provides a way to work with documents that
contain an implicit cross-reference structure
• <xsl:output>
• This instruction specifies how you want the result
tree to be output
XSLT, XPath and uPortal Some XSL Top Level Elements
• <xsl:param>
• Declares a parameter for a stylesheet or
template, and specifies a default value for the
parameter
• <xsl:template>
• Specifies a template rule.
• <xsl:variable>
• Declares a variable and binds a value to that
variable.
• The difference between the xsl:param and
xsl:variable instructions is that xsl:param defines
a default value while xsl:variable defines a fixed
value.
• If used as a top level element the scope is global
otherwise the scope is local to a specific template
XSLT, XPath and uPortal What Is a Template?
</xsl:stylesheet>
Dissected XSLT Stylesheet
Standard XML Namespace declaration for W3C XSLT
declaration namespace.
<xsl:template match="book">
This template <tr> xsl:sort is an XSLT instruction. The XSLT
matches book <td><xsl:value-of select="title" /></td> processor processes the book nodes in
elements in the <td><xsl:value-of select="author" /></td> alphabetical order by author.
source document. In <td align="right">
this stylesheet, the <xsl:value-of select="price" />
XSLT processor </td>
performs the actions </tr>
in this template xsl:value-of is an XSLT instruction. The
</xsl:template>
three times, once for XSLT processor extracts the contents of
each book element the source node specified in the select
</xsl:stylesheet> attribute and copies it into the result
in the source
document. document.
HTML Output Browser Representation
<html>
<head>
<META http-equiv="Content-Type" content="text/html">
<title>Stylesheet Example</title>
</head>
<body>
<table align="Center" cellpadding="5">
<tr>
<th>Title</th>
<th>Author</th>
<th>Price</th>
</tr>
<tr>
<td>The Divine Comedy</td>
<td>D. Alighieri</td>
<td align="right">5.95</td>
</tr>
<tr>
<td>Hamlet</td>
<td>W. Shakespeare</td>
<td align="right">2.95</td>
</tr>
<tr>
<td>Macbeth</td>
<td>W. Shakespeare</td>
<td align="right">9.95</td>
</tr>
</table>
</body>
</html>