XSLT XML Schema and XPath Matt Mc Clelland

  • Slides: 12
Download presentation
XSLT, XML Schema, and XPath Matt Mc. Clelland

XSLT, XML Schema, and XPath Matt Mc. Clelland

Introduction • XML Schema ▫ Defines the content and structure of XML data. •

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

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

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 e. Xtensible Stylesheet Language Transformations.

XSLT • What is XSLT? ▫ XSLT stands for e. Xtensible Stylesheet Language Transformations. ▫ Used in conjunction with XSL Stylesheets and XPath to render and style XML and other textbased documents.

XSLT (cont. ) Advantages Disadvantages • Clean, concise templates • Stylesheets may become difficult

XSLT (cont. ) Advantages Disadvantages • Clean, concise templates • Stylesheets may become difficult to maintain, especially if left unkempt • Relatively fast • Provides an easy, platform neutral way to render XML into HTML, PDF, and other XML docs • 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

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,

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.

Sample XML Specify XSL Stylesheet

Sample XML Specify XSL Stylesheet

XSLT Example classical. xsl <xsl: stylesheet xmlns: xsl="http: //www. w 3. org/TR/WD-xsl"> <xsl: template

XSLT Example classical. xsl <xsl: stylesheet xmlns: xsl="http: //www. w 3. org/TR/WD-xsl"> <xsl: template match="/"> <HTML> <HEAD><TITLE>Authors</TITLE></HEAD> <BODY> <H 1>Composers from Austria</H 1> <TABLE BORDER="1"><TR><TH>Name</TH></TR> <xsl: for-each select="/authors/author[nationality='Austrian']"> <TR><TD><xsl: value-of select="name" /></TD></TR> </xsl: for-each> </TABLE> </BODY> </HTML> </xsl: template> </xsl: stylesheet> XSL version XPath

Output Original XML Transformed XML

Output Original XML Transformed XML

Questions?

Questions?