Figure 3 AUTHORS-AND-TITLES.XSL <xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="t">
<li><xsl:value-of select="@title"/></li>
</xsl:template>
<xsl:template match="authors">
<h2><xsl:value-of select="concat(@au_fname, ' ',
@au_lname)"/></h2>
<ul>
<xsl:apply-templates select='document(concat("http://localhost/
pubs?sql=select title from
titleauthor ta, titles t where ta.title_id = t.title_id and
ta.au_id = '", @au_id,
"' for xml auto &root=results"))/results/t'/>
</ul>
</xsl:template>
<xsl:template match="/">
<html>
<body style="font-family:verdana;">
<h1>Pubs Authors</h1><hr/>
<xsl:apply-templates select='document("http://localhost/
pubs?sql=select * from authors for
xml auto&root=results")/results/authors'/>
</body>
</html>
</xsl:template>
</xsl:transform>
Figure 6 XSLT to HTML Table <xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="title_info/*">
<td><xsl:apply-templates/></td>
</xsl:template>
<xsl:template match="title_info">
<tr><xsl:apply-templates/></tr>
</xsl:template>
<xsl:template match="/">
•••
<table rules="all">
<xsl:apply-templates/>
</table>
•••
</xsl:template>
</xsl:transform>
Figure 7 Generating Table Headers with Modes <xsl:template match="title_info/*" mode="header">
<th><xsl:value-of select="name()"/></th>
</xsl:template>
<xsl:template match="title_info/*">
<td><xsl:apply-templates/></td>
</xsl:template>
<xsl:template match="title_info">
<xsl:if test="position()=1">
<xsl:apply-templates mode="header"/>
</xsl:if>
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
Figure 8 Using Recursion <xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="add | subtract | multiply | divide">
<xsl:variable name="op1">
<xsl:apply-templates select="*[1]"/>
</xsl:variable>
<xsl:variable name="op2">
<xsl:apply-templates select="*[2]"/>
</xsl:variable>
<xsl:if test="local-name() = 'add'">
<xsl:value-of select="$op1 + $op2"/>
</xsl:if>
<xsl:if test="local-name() = 'subtract'">
<xsl:value-of select="$op1 - $op2"/>
</xsl:if>
<xsl:if test="local-name() = 'multiply'">
<xsl:value-of select="$op1 * $op2"/>
</xsl:if>
<xsl:if test="local-name() = 'divide'">
<xsl:value-of select="$op1 div $op2"/>
</xsl:if>
</xsl:template>
</xsl:transform>
|