x.java, y.html, etc.
EAANILA1_7.zipAssignments dbxmlnml@acm.orgFirst write the xml document:
Example 7.1. letter.xml
<?xml version="1.0" encoding="UTF-8"?>
<emails>
<email>
<to>Mum</to>
<from>Porky</from>
<subject>Greetings</subject>
<message>Hello Mums, could you PLEASE send some more money</message>
</email>
</emails>
Here follows the first XSLT, key it into Eclipse:
Example 7.2. letter0.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<!-- 1st step -->
<xsl:template match="/emails/email">
<xsl:apply-templates select="*"/>
</xsl:template>
<!-- 2nd step -->
<xsl:template match="from">
From: <xsl:apply-templates/>
</xsl:template>
<xsl:template match="subject">
Subject: <xsl:apply-templates/>
</xsl:template>
<xsl:template match="message">
Message: <xsl:apply-templates/>
</xsl:template>
<xsl:template match="to">
To: <xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Key in both documents. Make your editor do the transformation. In Eclipse right click the xsl-document in the project explorer and run as XSLT Transformation pointing at the xml document. When you are done create a new version of the stylesheet:
Example 7.3. letter1.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
version="1.0">
<xsl:output method="xml"/>
<!-- 1st step -->
<xsl:template match="/emails/email">
<html>
<head><title>Letter</title></head>
<body><xsl:apply-templates/></body>
</html>
</xsl:template>
<xsl:template match="to">
<b>To: </b><xsl:apply-templates/><br />
</xsl:template>
<xsl:template match="from">
<b>From: </b><xsl:apply-templates/><br />
</xsl:template>
<xsl:template match="subject">
<b>Subject: </b><xsl:apply-templates/><br />
</xsl:template>
<xsl:template match="message">
<b>Message: </b><xsl:apply-templates/><br />
</xsl:template>
</xsl:stylesheet>
That sheet will transform the XML document to html.
Check out the results. Learn from your typing errors, and possibly do some experiments.
Try to think of creating notes when listening to a lecture, or a presentation. Then think of an XML format that might hold those notes. It could be context, date, lecturer, headline, notes etc.
Write an xml file with tags corresponding to your ideas. Put imaginary notes into the file from at least two different lectures, each containing at least two notes.