如果用户已经选择了格式化的视图,就会应用示例 5 中提供的 XSLT 代码。
代码示例 5. XSLT 格式化代码
<xsl:template match="table | TABLE | Table">
<table>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="tr | TR">
<tr>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="th | TH">
<th>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</th>
</xsl:template>
<xsl:template match="td | TD">
<td>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</td>
</xsl:template>
<xsl:template match="img | IMG | Img">
<img>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</img>
</xsl:template>
<table>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="tr | TR">
<tr>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="th | TH">
<th>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</th>
</xsl:template>
<xsl:template match="td | TD">
<td>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</td>
</xsl:template>
<xsl:template match="img | IMG | Img">
<img>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</img>
</xsl:template>
在这种情况下,转换产生示例 6 中提供的 HTML。
代码示例 6. 得到的格式化显示
<table border="5" cellpadding="5" cellspacing="5" bordercolor="#ffffff"
bgcolor="#ff9900" width="75">
<tr><td width="70"><img border="0" src="/enable/images/photos/man.jpg"
width="70" height="70" alt="Man with laptop"></td></tr>
<tr><td width="70"><img src="images/photos/hand.jpg" width="70"
height="70" border="0" alt="Hand on keyboard"></td></tr>
<tr><td width="70" align="middle"><img
src="images/photos/braille_fingers.gif" width="65" height="91"
valign="absmiddle" alt="Fingers feeling Braille text"
border="0"></td></tr>
</table>
