XSL & XSLT
XSL & XSLT
XSL
• XSL - Extensible stylesheet language
• style sheets for XML documents
• XSL describes how the XML document should be displayed
• XSL consists of four parts:
– XSLT - a language for transforming XML documents
– XPath - a language for navigating in XML documents
– XSL- FO - a language for formatting XML documents
– XQuery - a language for querying XML documents
XSLT
XSLT
XSLT
• With XSLT we can,
– add/remove elements and attributes to or
from the output file
– <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
– <xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
XSLT
• Steps
• XSL style sheet is an XML document, it always begins with the XML
declaration: <?xml version="1.0" encoding="UTF-8"?>.
• The next element, <xsl:stylesheet>, defines that this document is an
XSLT style sheet document (along with the version number and XSLT
namespace attributes).
• The <xsl:template> element defines a template. The match="/"
attribute associates the template with the root of the XML source
document.
• The content inside the <xsl:template> element defines some HTML to
write to the output.
• The last two lines define the end of the template and the end of the
style sheet
XSLT
• <xsl:value-of>
– Example
• <xsl:value-of select="catalog/cd/title"/>
• <xsl:value-of select="catalog/cd/artist"/>
XSLT
• <xsl:for-each> Element
- <xsl:for-each> element can be used to select every XML element of a
specified node-set
- Example:
<xsl:for-each select="catalog/cd">
<xsl:value-of select="title"/>
</xsl:for-each>
<xsl:template match=“OL”>
<xsl:copy />
<!-- this will copy the OL tag but leave all of its
subelements out -->
</xsl:template>