squeak!
Syllabus Homepage
Course Overview
Course resources
Day 1
Day 2
Day 3
Day 4
Common errors
Internet Glossary
About Your Instructor
Credits: This site powered by the vi text editor, apache webserver, perl scripting, and Debian linux.
squeak!

XML - Day 3

Goals

In this session you will:
  • use CSS to affect the layout of your xml document view
  • learn how XSL might be used to affect the layout of your xml document view
  • use XSLT to manipulate your data
  • use XSLT to transform your XML into another format

POST

  1. How can you supply a default value to an attribute from within a DTD?
  2. What is the difference between an ID and IDREF?
  3. When might you use an internal DTD?
  4. Bonus: what is the difference between IDREF and IDREFS?

CSS 1, 2, 3

CSS is explicitly used to control display of digital information.

XSL

Specifically designed to control display of XML documents, which have no default view (Remember MSIE is leveraging an internal CSS for its display).
XSL is still under development. The XSL language has changed radically in the past, and will change again in the future... To make matters worse, no software implements all of the Candidate Recommendation of XSL.... There are no Web browsers that can display a document written with XSL formatting objects. Eventually, of course, this should be straightened out as the standard evolves toward its final incarnation and more vendors implement XSL formatting objects.
  • MSXML 3.0 is W3 XSL compliant
  • XSL documents are XML rather than DTD-like
  • function of XSL
    • transform - XSLT
    • formatting - XSL Flow/Formatting Objects - minimally supported by IE.
      The XSL FO markup is quite complex. It is also verbose; virtually the only practical way to produce an XSL FO file is to use XSLT to produce a source document. Finally, once you have this XSL FO file, you need some way to render it to an output medium. There are few tools available to do this final step. For these reasons, XML FO has not caught on as quickly as XSLT.

    • define - XPath identifies nodes within an XML document for use with XPointer, complex XSLT etc. Not covered in our text
  • CSS uses selectors to associate objects with a rule. XSL uses templates to associate objects with a rule:

XSLT - transformation

XSLT is useful for selecting or re-ordering your XML data, or converting your XML to some other form of document.
  • How it works
    • declare the XML stylesheet <?xml:stylesheet href="petxslt2.xsl" type="text/xsl" ?>
    • match attribute associates the template with an element
      	<xsl:template match="match expression">
      		[transformation here]
      	</xsl:template>
      
    • <xsl:value-of select="xsl pattern"> element inlines xml content into the transformed document
    • <xsl:for-each select="xsl pattern"> element provides iteration
  • Hands-on
    • make a copy of your petstore.xml called petxsl.xml
    • create an XSL document to display part or all of your xml as HTML
    • add a sort <xsl:for-each select="xsl pattern" sort-by="+/-element">
    • add a filter: <xsl:for-each select="xsl pattern[element='foo']"> Note use of different delimiter. Comparator can be >, <, =, !=.
    • use a conditional: <xsl:if match=".[ARTIST='Bob Dylan']">your stuff here</xsl:if >
    • use choose: (case)
      	<xsl:choose>
      	<xsl:when test=".[ARTIST='Bob Dylan']">
      		... some code ...
      	</xsl:when>
      	<xsl:when test=".[ARTIST='Yngwie Malmsteen']">
      		... some code ...
      	</xsl:when>
      	<xsl:otherwise>
      	... some code ....
      	</xsl:otherwise>
      	<xsl:choose>
      	
  • A working example with XSLT

Homework

Manipulating the DOM p343- 358|217-225


http://www.mousetrap.net/syllabus/xml/day3.html
$Id: day3.orb,v 1.3 2001/10/31 02:58:09 mouse Exp $

Remember, your login is based on your machine's hostname, not on any other number.
~/[initials] refers to the subdirectory under your homedir, named after your initials. Everything except for .dotfiles will be stored in your ~/[initials] directory.


© 1995-2001 jason carr
Distributed under the terms of the GNU Free Documentation License.