📄 mailbox.xslt
字号:
<?xml version="1.0" encoding="UTF-8"?>
<!--
***********************************************************************
** An XSLT stylesheet for an Email viewer. Allows the user to
** logon, select from a list of folders, and sort a list of
** message headers.
********************************************************************-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
*********************************************************************
** global.curSortColumn : The stylesheet will sort on this column.
** global.sessionID : Used for URL-rewriting to implement
** session tracking without cookies.
******************************************************************-->
<xsl:param name="global.curSortColumn" select="'whenReceived'"/>
<xsl:param name="global.sessionID"/>
<!-- This stylesheet produces XHTML -->
<xsl:output method="xml" indent="yes" encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<!--
*********************************************************************
** This template produces the skeletal XHTML document.
******************************************************************-->
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mailbox Example</title>
<style type="text/css">
td, th {
border-right: 1px solid gray;
border-bottom: 1px solid gray;
}
table {
border-left: 1px solid gray;
border-top: 1px solid gray;
}
</style>
</head>
<body>
<!-- Create a form for this page -->
<form method="post" action="/chap8/mailbox{$global.sessionID}">
<h1>Mailbox Example</h1>
<xsl:apply-templates select="mailbox/username"/>
<xsl:apply-templates select="mailbox/folders"/>
<xsl:apply-templates select="mailbox/folder"/>
</form>
</body>
</html>
</xsl:template>
<!--
*********************************************************************
** This template produces the text field and button that allow
** users to log on.
******************************************************************-->
<xsl:template match="username">
<div>User Name:
<input type="text" size="10" name="username" value="{.}"/>
<input type="submit" name="logon" value="Logon"/>
</div>
</xsl:template>
<!--
*********************************************************************
** This template creates the <select> tag (a dropdown list) that
** allows users to select which folder to view.
******************************************************************-->
<xsl:template match="folders">
<p>
<xsl:text>Contents of: </xsl:text>
<select name="changeCurrentFolder" size="1">
<!-- for each <name>FolderName</name> element, produce
an <option> tag. -->
<xsl:for-each select="name">
<option value="{.}">
<!-- if this is the current folder, indicate that this
is the selected option -->
<xsl:if test=".=/mailbox/folder/name">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
<!-- Provide a button that submits the form -->
<input type="submit" name="changeFolderBtn" value="Change"/>
</p>
</xsl:template>
<!--
*********************************************************************
** This template creates a <table> that displays all message
** headers within the current <folder>.
******************************************************************-->
<xsl:template match="folder">
<!-- Use <span> to assign a CSS style -->
<span style="font-size: smaller;">
(click on a button to sort)</span>
<table cellpadding="2" cellspacing="0" border="0">
<!-- Each column heading may have a button. Delegate
to the "columnHeading" template for that logic -->
<tr bgcolor="#ccccff">
<xsl:call-template name="columnHeading">
<xsl:with-param name="column" select="'from'"/>
<xsl:with-param name="displayName" select="'From'"/>
</xsl:call-template>
<xsl:call-template name="columnHeading">
<xsl:with-param name="column" select="'to'"/>
<xsl:with-param name="displayName" select="'To'"/>
</xsl:call-template>
<xsl:call-template name="columnHeading">
<xsl:with-param name="column" select="'subject'"/>
<xsl:with-param name="displayName" select="'Subject'"/>
</xsl:call-template>
<xsl:call-template name="columnHeading">
<xsl:with-param name="column" select="'whenReceived'"/>
<xsl:with-param name="displayName"
select="'When Received'"/>
</xsl:call-template>
</tr>
<!-- determine how to sort -->
<xsl:choose>
<!--
*************************************************************
** When the current sort column has a "sortKey" attribute,
** use that for sorting. This uses a complex XPath
** location path:
** messageHeader/*[name() = $global.curSortColumn]/@sortKey
** It is broken down as follows:
** 1. messageHeader
** (select all <messageHeader> elems)
** 2. /*
** (select all children of <messageHeader>)
** 3. [name() = $global.curSortColumn]
** (narrow down the list to only include the child
** that is the current sort column)
** 4. /@sortKey
** (test to see if the child has a sortKey attribute)
**
**********************************************************-->
<xsl:when test="messageHeader/*[name() =
$global.curSortColumn]/@sortKey">
<xsl:apply-templates select="messageHeader">
<xsl:sort data-type="number" select="*[name() =
$global.curSortColumn]/@sortKey"/>
</xsl:apply-templates>
</xsl:when>
<!--
*************************************************************
** Otherwise, simply sort on the content of the current
** sort column. For instance, sort on the value of
** the <from>...</from> child of <messageHeader> if
** $global.curSortColumn="from"
**********************************************************-->
<xsl:otherwise>
<xsl:apply-templates select="messageHeader">
<xsl:sort select="*[name() = $global.curSortColumn]"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</table>
</xsl:template>
<!--
*********************************************************************
** This template creates a row in the table for an individual
** message header.
******************************************************************-->
<xsl:template match="messageHeader">
<!-- Make every other row a different color -->
<xsl:variable name="background">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">#cccccc</xsl:when>
<xsl:otherwise>#f0f0f0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr bgcolor="{$background}">
<td><xsl:value-of select="from"/></td>
<td><xsl:value-of select="to"/></td>
<td><xsl:value-of select="subject"/></td>
<td><xsl:value-of select="whenReceived"/></td>
</tr>
</xsl:template>
<!--
*********************************************************************
** This template creates an individual <th> tag for the table.
** If this is the current sort column, display text. Otherwise,
** display a button that the user can click on to sort.
******************************************************************-->
<xsl:template name="columnHeading">
<xsl:param name="column"/>
<xsl:param name="displayName"/>
<th>
<xsl:choose>
<!-- If this is the current sort column, simply
show the column display name -->
<xsl:when test="$column = $global.curSortColumn">
<xsl:value-of select="$displayName"/>
</xsl:when>
<!-- Otherwise, produce a button that the user can
click on to sort -->
<xsl:otherwise>
<input type="submit" name="sortOn{$column}"
value="{$displayName}"/>
</xsl:otherwise>
</xsl:choose>
</th>
</xsl:template>
</xsl:stylesheet>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -