90 likes | 198 Views
INFO 440: Information System Design Fall 2003 * Bob Boiko * MSIM Associate Chair. XML Transforms. Templates as Programs. Templates have processor programs that read them and form an output page. Templates as Programs.
E N D
INFO 440: Information System Design Fall 2003 * Bob Boiko * MSIM Associate Chair XML Transforms
Templates as Programs Templates have processor programs that read them and form an output page. INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
Templates as Programs <HTML> <HEAD>[Insert Title]</HEAD> <BODY>[Insert Body]</BODY></HTML> <xsl:template match="/"> <HTML> <xsl:apply-templates /> </HTML></xsl:template><xsl:template match="Title"> <TITLE> <xsl:value-of select="."/> </TITLE></xsl:template><xsl:template match="Body"> <BODY> <xsl:value-of select="."/> </BODY></xsl:template> <HTML> <HEAD>@@(Title)@@</HEAD> <BODY> <!– TemplateBeginEditable name=“head” --> <!– TemplateEndEditable --> </BODY></HTML> <HTML> <HEAD> <CMSCommand> <INSERT COMPONENT="ID" ELEMENT="Body"> <CUSTOMCOMMAND NAME="SectName" File="Myfunct.dll"/> </INSERT> </CMSCommand> </HEAD> <BODY> <INSERT COMPONENT="ID" ELEMENT="Body"/> </BODY></HTML> Function BuildPage(ID) Set Component = LoadComponent(ID) Title = Component.GetElement("title") Body = Component.GetElement("body") Output ("<HTML><HEAD>“) Output (Title) Output ("</HEAD><BODY>”) Output (Body) Output ("</Body></HTML>”)End Function <HTML> <HEAD><%=sTitle%></HEAD> <BODY><%=sTitle%> </BODY></HTML> INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
What is XSLT? • A way to transform XML • To HTML • To text • Not too good at other formats ( • A way to add formatting • A programming language • Not for end users • Not too hard for easy things • Will need to use “real” programming where it fails INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
Why use It? • Standardizes your publications • Reuse • Create one transform (i.e., XSL file) many pages • One content chunk many presentations • Assures well formed output • Separates processing code from presentation code (sort of) INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
Major Player XML • XSL is XML! • All the same rules apply <xsl:stylesheet> <xsl:templatematch="/"> <h1> <xsl:value-ofselect="//title"/> </h1> <h2> <xsl:value-ofselect="//author"/> </h2> </xsl:template></xsl:stylesheet> INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
Major Player Templates & XPath • The whole file is a stylesheet • Stylesheets have templates • Templates have selectors • Selectors use XPath • Templates contain value-of’s • Value-of’s contain selectors INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
Template Example Taken from http://www.zvon.org/xxl/XSLTutorial/Output/example1_ch1.html INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair
The Spy debug environment INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair