180 likes | 468 Views
XSLT, XML Schema, and XPath. Matt McClelland. Introduction. XML Schema Defines the content and structure of XML data. XSLT Used to transform XML documents into other XML documents or text-based formats such as HTML and PDF. XPath
E N D
XSLT, XML Schema, and XPath Matt McClelland
Introduction • XML Schema • Defines the content and structure of XML data. • XSLT • Used to transform XML documents into other XML documents or text-based formats such as HTML and PDF. • XPath • Used as a way to locate and tag “items” or nodes in an XML document.
XML Schema • What is an XML Schema? • XML Schema documents are used to define and validate the content and structure of XML Data. • Primarily used to separate content from formatting
XML Schema (cont.) • Follows Strict Hierarchical Structure • Every well-formed XML Schema document (.xsd) follows a tree-like structure • Contains root, child, and leaf nodes/tags • Restricts documents to a fixed vocabulary and validates documents to ensure they follow the rules of the dialect • Contains only Structural/Semantic Data • XML Documents contain NO formatting information..
XSLT • What is XSLT? • XSLT stands for eXtensible Stylesheet Language Transformations. • Used in conjunction with XSL Stylesheets and XPath to render and style XML and other text-based documents.
XSLT (cont.) Advantages Disadvantages • Clean, concise templates • Relatively fast • Provides an easy, platform neutral way to render XML into HTML, PDF, and other XML docs • Stylesheets may become difficult to maintain, especially if left unkempt • Not easily readable or understandable at a glance • Not supported by all web crawlers or older internet browsers
XPath • What is XPath? • XPath is a query language often used in conjunction with XSLT for selecting nodes from an XML document. • Addresses ‘parts’ of an XML document and provides basic facilities for computing and manipulating strings, numbers, and booleans from the content of an XML document.
XPath (cont.) • How does it work? • XPath uses a compact, string-based, rather than XML element-based syntax. • Operates on the abstract, logical structure of an XML document (tree of nodes) rather than its surface syntax. • Uses a path notation (much like URLs) to navigate through the XML’s hierarchical tree structure.
SpecifyXSL Stylesheet Sample XML
XSL version XPath XSLT Example classical.xsl <xsl:stylesheetxmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <HTML> <HEAD><TITLE>Authors</TITLE></HEAD> <BODY> <H1>Composers from Austria</H1> <TABLE BORDER="1"><TR><TH>Name</TH></TR> <xsl:for-each select="/authors/author[nationality='Austrian']"> <TR><TD><xsl:value-ofselect="name" /></TD></TR> </xsl:for-each> </TABLE> </BODY> </HTML> </xsl:template> </xsl:stylesheet>
Output Original XML Transformed XML