X hits on this document

478 views

0 shares

1 downloads

0 comments

55 / 142

Transforming XML with XSLT

</xsl:for-each>

</xsl:template> </xsl:stylesheet>

SQL created by the XSLT file above looks like this:

INSERT INTO pets INSERT INTO pets INSERT INTO pets INSERT INTO pets INSERT INTO pets INSERT INTO pets

(name, age,

type,

(name, age,

type,

(name, age,

type,

(name, age,

type,

(name, age,

type,

(name, age,

type,

color)

WITH VALUES

color)

WITH VALUES

color)

WITH VALUES

color)

WITH VALUES

color)

WITH VALUES

color) WITH VALUES

('Tilly', '14', 'cat', 'silv ('Amanda', '10', 'dog', 'bro ('Jack', '3', 'cat', 'black'

('Blake',

'12',

('Loosey',

'1',

'dog',

'blue

'cat',

'brow

('Stop',

'5',

'pig',

'brown'

This file could then be feed to a relational database program that understands SQL and populate a table with data.

This section barely scratched the surface of XSLT. It is an entire programming language unto itself and much of the promise of XML lies in the exploitation of XSLT to generate various types of output be it output for Web browsers, databases, or input for other computer programs.

Exercise - XML to XHTML

[INSERT letter2xhtml.xsl HERE]

Exercise - Displaying TEI files in your browser

In this exercise you will learn how to use your Web browser to transform and display XML data using TEI files as examples. This exercise assumes you are using a rather modern browser such as a newer version of Mozilla, Firefox, or Internet Explorer since these browsers have XSLT transformation capab- ility built-in.

  • 1.

    Open the XSLT stylesheet xslt/tei2html.xsl in your Web browser. Notice how it initializes a valid XHTML DTD declaration as well as provides the framework for rich metadata in the head element. Notice how the content of the body is created by searching the document for div1 tags to build a ta- ble of contents. Finally, notice how the balance of the body's content is created by trapping a lim- ited number of TEI elements and transforming them into HTML.

  • 2.

    Open a TEI file, say xml-data/tei/machiavelli-prince-1081003648.xml in your Web browser. It should display the raw XML data.

  • 3.

    Open xml-data/tei/machiavelli-prince-1081003648.xml in your favorite text editor and make the following text the second XML processing instruction in the file: <?xml-stylesheet type='text/xsl' href='../../xslt/tei2html.xsl'?>. In other words insert the processing instruction before the beginning of the DTD declaration. Save the edited file.

  • 4.

    Open, again, xml-data/tei/machiavelli-prince-1081003648.xml in your Web browser. If all goes well, then you should see nicely rendered text that is more human readable than the raw XML. This

47

Document info
Document views478
Page views484
Page last viewedSun Dec 11 02:34:44 UTC 2016
Pages142
Paragraphs3126
Words34660

Comments