Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Objectives
After completing this lesson, you should be able to do
the following:
Describe XSL and XSL Transformations (XSLT)
Transform an XML document by using XSLT
Use key XSLT elements
Create, apply, and call templates
Sort and filter an XML document
Use parameters with templates
Use the oraxsl command-line utility
6-2
What Is XSL?
Extensible Stylesheet Language (XSL) is made up of
two parts:
XSL Transformations (XSLT)
XSL Formatting Objects (XSL-FO)
XSL
6-3
XSL Transformations
Input XML
document
XSL
processor
Output
XML
document
XSL
stylesheet
Matchin
g
rule
6-4
<?xml version="1.0"?>
<xsl:stylesheet ...>
<xsl:template match="XPath"/>
<!-- output information -->
</xsl:template>
</xsl:stylesheet>
Copyright 2004, Oracle. All rights reserved.
Output
data
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
...
<xsl:template match="/"> ... </xsl:template>
<xsl:template match="..."> ... </xsl:template>
<xsl:stylesheet>
6-5
1
2
3
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="emp.xsl"?>
<employees>
<employee>
<employee_id>100</employee_id>
<last_name>King</last_name>
<salary>24000</salary>
</employee>
<employee>
<employee_id>101</employee_id>
<last_name>Kochhar</last_name>
<salary>18000</salary>
</employee>
</employees>
6-8
<xsl:template match="pattern">
output-template
</xsl:template>
<xsl:template match="/">
A simple text string
</xsl:template>
6-9
1 Europe
Output document
B
B
C
Input XML
document
6-11
Document root
<xsl:template match="/">
Document root
<xsl:apply-templates/>
</xsl:template>
A
D
<xsl:template match="A">
Root element A
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="B">
Element B
</xsl:template>
Copyright 2004, Oracle. All rights reserved.
Output
Document
Document root
Root element A
Element B
Element B
6-13
6-14
2
<xsl:element name="region">
<xsl:attribute name="id">5</xsl:attribute>Japan
</xsl:element>
<region id="5">Japan</region>
3
<xsl:attribute-set name="region-info">
<xsl:attribute name="id">5</xsl:attribute>
<xsl:attribute name="name">Japan</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="region[1]">
<xsl:element name="{local-name()}"
use-attribute-sets="region-info">
</xsl:element>
</xsl:template>
<region id="5" name="Japan"/>
6-18
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/employees">
<xsl:for-each select="employee">
<xsl:sort select="last_name"/>
<p><xsl:value-of select="."/></p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
6-19
6-20
6-22
Summary
In this lesson, you should have learned how to:
Create an XSL stylesheet containing XSLT
elements
Use XSLT to transform an XML document by using
a browser and the oraxsl command-line utility
Use <xsl:template> to create a template rule
Use <xsl:apply-templates> for recursion
through child template rules
Call named templates with <xsl:call-template>
with and without parameters
Apply sort criteria to nodes in an XML document
by using the <xsl:sort> element
6-23