另一方面,如果用户已经选择了页面的纯文本视图,就会应用该 XSLT 代码,如示例 7 中所示。
代码示例 7. XSLT 纯文本代码
<xsl:template match="table | TABLE | Table">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="tr | TR">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="th | TH">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="td | TD">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="img | IMG | Img">
<xsl:if test="not(ancestor::banner) and not(ancestor::BANNER) and
not(ancestor::Banner)">
<xsl:for-each select="@*">
<xsl:if test="((name()='alt') or (name()='ALT') or
(name()='Alt')) and (normalize-space(.)!='')">
[image: <xsl:value-of select="." />]
</xsl:if>
</xsl:for-each>
<xsl:apply-templates />
</xsl:if>
</xsl:template>
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="tr | TR">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="th | TH">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="td | TD">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="img | IMG | Img">
<xsl:if test="not(ancestor::banner) and not(ancestor::BANNER) and
not(ancestor::Banner)">
<xsl:for-each select="@*">
<xsl:if test="((name()='alt') or (name()='ALT') or
(name()='Alt')) and (normalize-space(.)!='')">
[image: <xsl:value-of select="." />]
</xsl:if>
</xsl:for-each>
<xsl:apply-templates />
</xsl:if>
</xsl:template>
示例 8 产生一个简单得多的数据视图。
代码示例 8. 得到的纯文本显示
<div>
<div>
<div>
[image: Man with laptop]
</div>
</div>
<div>
<div>
[image: Hand on keyboard]
</div>
</div>
<div>
<div>
[image: Fingers feeling Braille text]
</div>
</div>
<div>
<div>
[image: Man with laptop]
</div>
</div>
<div>
<div>
[image: Hand on keyboard]
</div>
</div>
<div>
<div>
[image: Fingers feeling Braille text]
</div>
</div>
正如您能看到的,表已由 DIV 替换,图像和格式设置已移除,而且每个图像的 ALT 属性替换了该图像。
上面所描述的技术提供了一组既带有丰富视图又带有纯文本视图的数据。由于数据不是重复的,因此更新站点只需更新一组数据页面。
