Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Objectives
In this session, you will learn to:
Use the <xsl:include> element
Use various XSLT functions
Categorize different types of CSS style sheets
Use the class attribute
Ver. 1.0
Slide 1 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
The <xsl:include> Element
Enables you to treat style sheets as modular units
Used to include another style sheet in the current style
sheet
Is the child element of the <xsl:stylesheet> element or
the <xsl:transform> element
The following code snippet illustrates the use of the
<xsl:include> element:
<xsl:stylesheet version “1.0”
xmlns:xsl=”http://www.w3.org/1999/xsl/Transfor
m”>
<xsl:include href=”other_stylesheet.xsl”/>
</xsl:stylesheet>
Ver. 1.0
Slide 2 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
XSLT Functions
XSLT provides more than 100 inbuilt functions
The following table lists the various functions provided by
XSLT:
Method Name
Ver. 1.0
Description
Example
current()
Used to return the
reference of the
current node.
<xsl:value-of select="current()"/>
format-number()
Used to convert a
number to a string.
<xsl:value-of select='formatnumber(500100, "###,###.00")' />
System-property()
Used to return the
value of the system
property specified by
the parameter.
<xsl:value-of select="systemproperty('xsl:version')" />
<br />
<xsl:value-of select="systemproperty('xsl:vendor')" />
<br />
Slide 3 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
XSLT Functions (Contd.)
The following table lists the various functions provided by
XSLT (Contd.):
Method Name
Key()
Ver. 1.0
Description
Example
Used to return a
node-set using the
index specified by an
<xsl:key> element.
<xsl:key name="studentList"
match="Student" use="Score" />
.
.
<xsl:template match="/">
<xsl:for-each select="key('studentList',
'100')"> <p>Title: <xsl:value-of
select="Rollno"/> <br/> Artist: <xsl:valueof select="Name"/> <br/>
Price: <xsl:value-of select="Score"/></p>
</xsl:for-each></xsl:template>
Slide 4 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
XSLT Functions (Contd.)
The following table lists the various functions provided by
XSLT (Contd.):
Method Name
Key()
Ver. 1.0
Description
Example
The preceding code displays the Roll Number,
Name, and Score of all students with score 100,
where the XML file has the following structure:
<StudentDetails>
<Student>
<Rollno>1</Rollno>
<Name> Tom </Name>
<Score>100</Score>
</Student>
<Student>
<Rollno>2</Rollno>
<Name> Jack </Name>
<Score>90</Score>
</Student>
.
.
</StudentDetails>
Slide 5 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Types of CSS Style Sheets
Can be used for formatting both HTML and XML documents
Can be one of the following types:
Inline:
Can be used only for the HTML element in which it appears
Cannot be reused for other elements, even within the same
document
Can only be used in HTML and not in XML
The following example illustrates its use:
<p style="color: red; margin-left: 10px">
This is a sample paragraph
</p>
Embedded:
Is embedded within an XML document
Cannot be used for other XML documents
Ver. 1.0
Slide 6 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Types of CSS Style Sheets (Contd.)
Embedded (Contd.):
The following code uses an embedded CSS stylesheet:
<?xml-stylesheet href="#style" type="text/css"?>
<article>
<extras id="style">
headline { display: block }
headline { color: red }
content { display: block }
content { color: blue }
extras { display: none }
</extras>
<headline>This is the headline of the
article</headline>
<content>This is the content of the
article</content>
</article>
Ver. 1.0
Slide 7 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Types of CSS Style Sheets (Contd.)
External:
Is external to the XML document
Formatting instructions are saved in an external file that can be
imported in any number of XML documents
The following code uses an external CSS stylesheet:
<?xml-stylesheet href="my-style.css" type="text/css"?>
<article>
<headline>this is the headline of the
article</headline>
<content>this is the content of the
article</content>
</article>
The my-style.css file contains the following text:
headline { display: block }
headline { color: red }
content { display: block }
content { color: blue }
Ver. 1.0
Slide 8 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Class Attribute
Used to apply different CSS styles to the same type of
elements
The following code snippet depicts the usage of the class
attribute:
<heading class="red">This heading is
red.</heading>
<heading class="green">This heading is
green.</heading>
Ver. 1.0
Slide 9 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Best Practices
External style sheets should be preferred over embedded
style sheets because they provide better management of
code and more control over rendering. External style sheets
enable you to keep the formatting instructions separate from
the content, thereby serving one of the key purposes of
using style sheets. The following benefits are available
when you use external style sheets:
External style sheets are reusable. This eliminates the need for
creating separate style sheets for documents that require the
same formatting.
External style sheets allow consistent rendering of XML
documents. An external style sheet can be created and
associated with XML documents to render any number of XML
documents in a particular format. This is not easily achievable
through inline or embedded style sheets.
Ver. 1.0
Slide 10 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Best Practices (Contd.)
Unlike inline and embedded style sheets, the formatting of
XML documents can be easily updated by updating the
corresponding external style sheet.
External style sheets enable you to keep the XML documents
light. As a result, the XML documents download faster than
when used with inline or embedded style sheets.
Ver. 1.0
Slide 11 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Tips and Tricks
You should ensure that the value of the class attribute in the
XML document exactly matches the string that appears after
the period in the corresponding class selector. Otherwise,
the style rule will not apply to the element.
You can either create a complex data type, or a group to
define a group of elements that can be referred to at
multiple places in an XML schema. Groups are preferred
over complex data types because they are easier to
implement than complex data types. Complex data types
should be used when you need to specify attributes. This is
because, groups allow you to specify only elements and not
attributes.
Ver. 1.0
Slide 12 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Tips and Tricks (Contd.)
You should use an XML editor to create XML documents.
An XML editor helps in creating an error free and wellformed XML document. It can also be used to validate the
XML document against a schema. Some examples of XML
editors are XMLSpy, Stylus Studio, and, oXygen.
Ver. 1.0
Slide 13 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
FAQs
How is an XML source document connected to an XSL style
sheet?
You can connect an XSLT style sheet with an XML source
document by declaring a processing instruction in the XML
document. The processing instruction needs to be placed
before the root element and after the XML version declaration
to connect an XML document to its style sheet. The following
code snippet connects the sample.xsl file with an XML
document:
<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl"
href="sample.xsl"?>
<root>
...
</root>
Ver. 1.0
Slide 14 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
FAQs (Contd.)
Can both CSS and XSLT be used together in an XML
document?
Yes. You can use XSLT to transform XML data into structures,
such as lists and tables, and then apply CSS to the result to
control how these structures appear in the resulting Web page.
Do all XML parsers support XSLT?
No, all XML parsers do not support XSLT. For example,
Apache Xerces, a Java-based parser does not support XSLT.
If a user wants to perform XSL transformations by using
Apache Xerces, the user needs to use the XALAN parser.
XALAN is an XSLT parser for transforming XML documents
into HTML, text, or other XML document types. Microsoft’s
MSXML parser provides an edge in this regard, as it supports
XSLT and does not require additional XSLT parsers for XSL
transformations.
Ver. 1.0
Slide 15 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
FAQs (Contd.)
Why is the xsl:apply-templates element used?
The xsl:apply-templates element is used in templatesbased formatting. This element directs the XSLT processor to
find and apply the appropriate xsl:template.
Ver. 1.0
Slide 16 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge
Which of the following code snippets can be used in an XML
document named Test.xml to associate it with a style sheet
named Test.css?
<?xml-stylesheet href="Test.css"
type="text/css"?>
<?xml-stylesheet href="Test.xsl"
type="text/css"?>
<?xmlstylesheet href="Test.css"
type="text/xsl"?>
<xml-stylesheet href="Test.css"
type="text/css"/>
Answer:
<?xml-stylesheet href="Test.css"
type="text/css"?>
Ver. 1.0
Slide 17 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
A user is creating a schema for an XML document. The user
wants to refer an external schema, which is stored in the
product.xsd file. The target namespace of both the external
schema and the current schema is the same. Which of
following code snippets should the user use to refer to this
schema?
<include Location= "product.xsd"/>
<include schemaLocation= "product.xsd"/>
<import schemaLocation= "product.xsd"/>
<import Location=" product.xsd"/>
Answer:
<include schemaLocation= "product.xsd"/>
Ver. 1.0
Slide 18 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
A user is creating a schema for an XML document. In the
schema, the user wants to include the declaration for the
employee element and its three child elements: name,
designation, and salary. The user wants that the child
elements of employee may appear in any sequence in the
XML document. Which of the following code snippets should
the user use to declare the employee element?
<xsd:complexType name="employee">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="designation"
type="xsd:string"/>
<xsd:element name="salary"
type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
Ver. 1.0
Slide 19 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
<xsd:complexType name="employee">
<xsd:group>
<xsd:element name="name"
type="xsd:string"/>
<xsd:element name="designation"
type="xsd:string"/>
<xsd:element name="salary"
type="xsd:string"/>
</xsd:group>
</xsd:complexType>
Ver. 1.0
Slide 20 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
<xsd:complexType name="employee">
<xsd:choice>
<xsd:element name="name"
type="xsd:string"/>
<xsd:element name="designation"
type="xsd:string"/>
<xsd:element name="salary"
type="xsd:string"/>
</xsd:choice>
</xsd:complexType>
Ver. 1.0
Slide 21 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
<xsd:complexType name="employee">
<xsd:all>
<xsd:element name="name"
type="xsd:string"/>
<xsd:element name="designation"
type="xsd:string"/>
<xsd:element name="salary"
type="xsd:string"/>
</xsd:all>
</xsd:complexType>
Ver. 1.0
Slide 22 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
Answer:
<xsd:complexType name="employee">
<xsd:group>
<xsd:element name="name"
type="xsd:string"/>
<xsd:element name="designation"
type="xsd:string"/>
<xsd:element name="salary"
type="xsd:string"/>
</xsd:group>
</xsd:complexType>
Ver. 1.0
Slide 23 of 24
Installing
Windows
Professional
Using
Attended Installation
Introduction
toXP
Web
Content
Development
Challenge (Contd.)
A user is creating a schema for an XML document. In the
schema, the user wants to create a group of attributes that
can be reused with different elements. Which of the
following XSD elements should the user use for this
purpose?
group
attribute
attributeGroup
choice
Answer:
attributeGroup
Ver. 1.0
Slide 24 of 24
© Copyright 2026 Paperzz