200 likes | 278 Views
Using XSLT To Transform XML Brian E. Travis Architag International Corp btravis@architag.com 9-333. XSL Extensible Stylesheet Language. HTML: "Format without Structure" Typesetting language Not extensible CSS: "Enhanced Format, No Structure" Stylesheet language
E N D
Using XSLT To Transform XMLBrian E. TravisArchitag International Corpbtravis@architag.com9-333
XSLExtensible Stylesheet Language • HTML: "Format without Structure" • Typesetting language • Not extensible • CSS: "Enhanced Format, No Structure" • Stylesheet language • Overrides default formatting for HTML, but annot change basic structure of the document • XML: "Structure Without Format" • Defines "elements" using "tags" • Creates hierarchical structure of information set
XSLT"Adding Format to Structure" • Transforms XML to XML • Declarative programming language • Creates formatted output • Does limited processing
May 5, 2000 <I>May 5, 2000</I> <birthday>May 5, 2000</birthday> Quiz
XSLT Operation Source Tree (your XML) XSLT Output (x) XSL Transformer Stylesheet xmlns:xsl
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ... </xsl:stylesheet> Start tag for stylesheet document, containing XSL Namespace indicator Template rules and other stuff End of stylesheet XSLT Stylesheet Architecture
XSLT Template Rule <xsl:template match="chapter/title"> <DIV STYLE="font-family:sans-serif; font-weight:bold; color:blue;"> <xsl:apply-templates/> </DIV> </xsl:template>
XSLT Template Rule <xsl:template match=“something”/> <xsl:apply-templates/> <xsl:value-of/>
XSLT Stylesheet <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="weather"> <H1><xsl:value-of select="@type"/></H1> <xsl:apply-templates/> <HR/> </xsl:template> <xsl:template match="temp"> <LI>Temperature <xsl:apply-templates/>°F</LI> </xsl:template> <xsl:template match="wind"> <LI>Wind: <xsl:apply-templates/>mph</LI> </xsl:template> <xsl:template match="text()"> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet>
XSLT Transformation <weather type="Current conditions"> <temp>76</temp> <wind>5</wind> </weather> <wind>5</wind> <temp>76</temp> 8 76 1 5 3 5 10 6 2 7 4 13 9 11 12 <H1>Current conditions</H1> <LI>Temperature: 76 °F</LI> <LI>Wind: 5 mph</LI> <HR/>
Demonstration: XSL for Documents • Create stylesheet for complex document • Run in browser
Demonstration: XSL On The Server • Get XML document from server • Article.xml • Apply stylesheet, transform, and deliver HTML to the browser • Article.asp • Article.xsl
XSL(Abstract) XSL (Full) XSL (TOC) XML XSL Processor (HTML) XSLT Operation HTML (TOC) HTML (Abstract) HTML (Full)
Demonstration: XML Data Islands • Create HTML document with XML data islands • Article.xml • Article-toc.xsl • Article-abstract.xsl • Article-full.xsl • Article-wtoc.xsl • Switch stylesheet under script control • ApplyStyle.htm
Case Study: <TAG> Newsletter XML-enabled Web Site http://tagnewsletter.com
</Tutorial> • Tech Ed 2000 Materials • http://architag.com/r/TechEd2000 • XML and XSL • http://msdn.microsoft.com/xml • http://www.w3.org/Style/XSL/