The Information School at the University of Washington INFO 440: Information System Design Fall 2003 * Bob Boiko * MSIM Associate Chair XML Transforms The Information School at the University of Washington 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 The Information School at the University of Washington Templates as Programs <HTML> <xsl:template match="/"> <HEAD>[Insert Title]</HEAD> <HTML> <HTML> <BODY>[Insert Body]</BODY> <HEAD>@@(Title)@@</HEAD> </HTML> <HTML> <xsl:apply-templates /> <BODY> <HEAD> <!– TemplateBeginEditable name=“head” --> </HTML> <CMSCommand> Function BuildPage(ID) <!– TemplateEndEditable --> </xsl:template> COMPONENT="ID" ELEMENT="Body"> </BODY> Set <INSERT Component = LoadComponent(ID) <xsl:template match="Title"> <CUSTOMCOMMAND <HTML> NAME="SectName" File="Myfunct.dll"/> </HTML> Title</INSERT> = Component.GetElement("title") <TITLE> <HEAD><%=sTitle%></HEAD> Body = Component.GetElement("body") </CMSCommand> <xsl:value-of select="."/> <BODY><%=sTitle%> </BODY> Output ("<HTML><HEAD>“) </HEAD> </HTML> </TITLE> <BODY>(Title) Output </xsl:template> <INSERT COMPONENT="ID" ELEMENT="Body"/> Output ("</HEAD><BODY>”) </BODY> <xsl:template match="Body"> Output (Body) <BODY> </HTML> Output ("</Body></HTML>”) <xsl:value-of select="."/> End Function </BODY> </xsl:template> INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair The Information School at the University of Washington 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 The Information School at the University of Washington 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 The Information School at the University of Washington Major Player XML • XSL is XML! • All the same rules apply <xsl:stylesheet> <xsl:template match="/"> <h1> <xsl:value-of select="//title"/> </h1> <h2> <xsl:value-of select="//author"/> </h2> </xsl:template> </xsl:stylesheet> INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair The Information School at the University of Washington 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 The Information School at the University of Washington 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 Information School at the University of Washington The Spy debug environment INFO 440: Information System Design * Fall 2004 * Bob Boiko * MSIM Associate Chair