2. What is XSL?
• XSL is a language that allows one to describe a browser
how to process an XML file.
• XSL can convert an XML file into another XML with
different format.
• XSL can convert an XML file into a non-XML file.
2
3. Purpose
• The most common type of XSL processing is to convert XML file
into HTML file which can be displayed by browsers. We will
focus on this use of XSL.
• XSL is the bridge between XML and HTML.
• We can use XSL to have different HTML formats for
the same data represented in XML.
• Separating data (contents) from style tags (display
commands).
3
14. XSl:copy
• Copying:
• xsl:copy, copies the current node
• xsl:apply-templates, processes the children of the current node
• ex. <xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
• <xsl:template match="title">
• <xsl:copy>
• <xsl:apply-templates/>
• </xsl:copy>
• </xsl:template>
• </xsl:stylesheet>
• xsl:copy-of element, can copy the entire subtree of each node that the
template selects
– ex. <xsl:template match="title“>
– <xsl:copy-of select="*"/>
– </xsl:template>
14
15. Example of Turning XML into HTML
• <?xml version="1.0"?>
• <?xml-stylesheet type="text/xsl" href="FitnessCenter.xsl"?>
• <FitnessCenter>
• <Member level="platinum">
• <Name>Jeff</Name>
• <Phone type="home">555-1234</Phone>
• <Phone type="work">555-4321</Phone>
• <FavoriteColor>lightgrey</FavoriteColor>
• </Member>
• </FitnessCenter>
15
16. HTML Document in an XSL Template
<?xml version="1.0"?>
<xsl:output method="html"/>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Welcome</TITLE>
</HEAD>
<BODY>
Welcome!
</BODY>
</HTML>
</xsl:template>
16