Extensible Stylesheet Language Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT
Jan 01, 2016
Extensible Stylesheet LanguageExtensible Stylesheet Language
Chao-Hsien Chu, Ph.D.School of Information Sciences and Technology
The Pennsylvania State University
XSL-FOXSLT
Ways of Displaying XMLWays of Displaying XML
Format
Information(Document)
Structure(DTD)
XSL
DHTML + CSS
DSSSL
CGI + Script
XML for Information InterchangeXML for Information Interchange
CADPackage
WordProcessor
StatisticalProcessing
SpreadsheetPackage
XML
SourceDocument
ResultDocument
ResultDocument
ResultDocument
ResultDocument
Extensible Stylesheet LanguageExtensible Stylesheet Language
XSL
XSLT
XSL-FO
Formatting Objects:To define the regions of a page and the appearance of content within those regions
Transformations:To specify how an XML document be transformed from one kind of document to another kind of document.
Concepts of XSLTConcepts of XSLT
XMLSource
Document
ResultingDocument
XSLStylesheet
XSLProcessor
Example of XSL ProcessorExample of XSL Processor
XT. www.jclark.com/xml/xt.html
LotusXSL. www.alphaworks.ibm.com/tech/LotusXSL
MSXML. www.microsoft.com/xml/xsl/
Xalan-Java. xml.apache.org/xalan-j/index.html
MDC-XSL. mdc-xsl.sourceforge.net/
XSL FAQ. www.dpawson.co.uk/xsl/xslfaq.html
Potential Usages of XSLTPotential Usages of XSLT Change the styles of a document. Add elements specifically for viewing, such as add the
logo or the address of the sender to an XML invoice. Create new contents from an existing one, such as create
the table of contents. Present information with the right level of details for the
readers, such as high-level information for top managers and detailed technical information to the rest of the staffs.
Convert between different DTDs or different versions of a DTD, such as convert a company specific DTD to an industry standard.
Transform XML documents into HTML for backward compatibility with existing browsers.
Write One Publish Many IdeaWrite One Publish Many Idea
XMLDocument
Print out
CD ROM
Web
WAP, etc.
Process
Process
Process
Process
SourceDocument
ResultDocuments
XSLT
Example of XSLT DocumentExample of XSLT Document
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns="http://www.w3.org/TR/REC-html40" result-ns=""><xsl:template match = "/"> <HTML> <HEAD> <TITLE>Customer Contact</TITLE> </HEAD> <BODY> <xsl:apply-templates select="Address_Book"/> </BODY> </HTML></xsl:template>
Process Instruction
RootElement
Elements
Subroutine
Example of XSLT DocumentExample of XSLT Document
<xsl:template match = "Address_Book"> <xsl:for-each select="Contact"> <UL> <LI> <xsl:value-of select="Name"/></LI> <UL> <LI>ID: <xsl:value-of select="ID"/></LI> <LI>EMAIL: <xsl:value-of select="EMAIL"/></LI> <LI>Phone: <xsl:value-of select="Phone"/></LI> <LI>Street: <xsl:value-of select="Address/Street"/></LI> <LI>City: <xsl:value-of select="Address/City"/></LI> <LI>State: <xsl:value-of select="Address/State"/></LI> <LI>ZIP: <xsl:value-of select="Address/ZIP"/></LI> </UL> </UL> </xsl:for-each></xsl:template>
</xsl:stylesheet>
Loop
Producing output
Element Attribute
XSL Document TreeXSL Document Tree
Address_Book
Contact
IDName E-mail Phone Address
ZipStateCityStreet
Root Element
Root ( / )
Elements of XSLT DocumentElements of XSLT Document
Structure. Concerned with the structure of the XSLT doc.
Content. Concerned with outputting content of the elements or attributes.
Looping and Decision Making. Used to loop and to carry out conditional operations
Manipulation. Used to manipulate, insert and copy elements from the source tree into the result tree.
Elements for StructureElements for Structure
<xsl:stylesheet> </xsl:stylesheet>. The root element of the XSL Document.
<xsl:output/>. To specify the final format (text, HTML, XML, WML, etc.) of the transformations.
<xsl:template> </xsl:template>. To define a template for producing output.
<xsl:apply-templates/>. To invoke other templates within the current template.
Examples of Output ElementExamples of Output Element
<xsl:output method=“text” indent=“no” />
<xsl:output method=“xml” version=“1.0”
indent=“yes” />
<xsl:output method=“xml” version=“1.0”
indent=“true”doctype-system=http://www.wapforum.org/DTD/wml_1.2.xml
doctype-public=“-//WAPFORUM//DTD WML 1.2//EN” />
Elements for ContentElements for Content
• <xsl:text> </xsl:text>. To write literal text to the output while preserving white space and of disabling output escaping.
• <xsl:value-of/>. To output the contents of the element or attribute given in the specified node (in Xpath expression). It has an attribute called “select” to define the source of output.
Looping & Decision Making ElementsLooping & Decision Making Elements
• <xsl:for-each> </xsl:for-each>. To carry out the transformation on each element that meets the criteria in “select” attribute.
• <xsl:if> </xsl:if>. Similar to the “if” statement. • <xsl:choose> </xsl:choose>. Similar to “if …
else” or “switch” structure.• <xsl:when> </xsl:when> and <xsl:otherwise>
</xsl:otherwise>. Allow us to select from one of several choices and to ensure that there is also a default action associated with this operation.
Elements for ManipulationElements for Manipulation
• <xsl:copy> </xsl:copy>. To copy elements in the source tree to the output.
• <xsl:copy-of/>. To copy the specified element in “select” attribute to the output.
• <xsl:element></xsl:element>. To create/insert a new element in the result tree.
• <xsl:attribute> </xsl:attribute>. To create/insert a new attribute in the result tree.
• <xsl:attribute-set> </xsl:attribute-set>. To define and name a set of attributes that always go together.
• <xsl:sort/>. To specify the sort order for the <xsl:apply-templates> and <xsl:for-each> elements.
Notations in Xpath ExpressionNotations in Xpath Expression
• “/” - root node
• “..” - parent node
• “.” - current context node
• “/parent/child”
• “*”- All the child nodes of the context node
• “@” - attribute node
• “//” - recursive descent operator (every)
Functions in Xpath ExpressionFunctions in Xpath Expression
name(): return the name of the node
position(): return the position of the node
count(): counts the number of occurrences of the item specified as a parameter
sum(): adds the values of the contents of the nodes passed to it.
Top Element for Different StylesheetsTop Element for Different Stylesheets
HTML Document:<xsl:stylesheet xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40">
Text File:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
XML Document:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes"/>
WML Document:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml“ version="1.0“ indent="true" doctype-system="http://www.wapforum.org/DTD/wml_1.2.xml" doctype-public="-//WAPFORUM//DTD WML 1.2//EN" />
How to Use XT ProcessorHow to Use XT Processor
Copy XT.exe to the directory where your XML sources are stored. (make sure that your directory structure are simple)
Activate the DOS mode (Command Prompt).
Switch to directory where XML sources are located. Use c: (for instance), then cd xxx.
Enter: XT xxx.xml xxx.xsl (shown on screen)
XT xxx.xml xxx.xsl >> file.xxx (saved in file.xxx)
Thank You?
Any Question?