Improved alt text handling and added/fixed support for numerous other tags.

This commit is contained in:
Gerald Schmidt 2009-12-03 19:33:48 +00:00
parent b937107f39
commit 08641acec4
4 changed files with 194 additions and 137 deletions

View File

@ -1,96 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="b"> <xsl:template match="b">
<!-- b not available --> <!-- b not available -->
<strong> <strong>
<xsl:apply-templates/> <xsl:apply-templates/>
</strong> </strong>
</xsl:template> </xsl:template>
<xsl:template match="i"> <xsl:template match="i">
<!-- i not available --> <!-- i not available -->
<em> <em>
<xsl:apply-templates/> <xsl:apply-templates/>
</em> </em>
</xsl:template> </xsl:template>
<xsl:template match="br"> <xsl:template match="br">
<br/> <br/>
</xsl:template> </xsl:template>
<xsl:template match="u"> <xsl:template match="u">
<!-- deprecated --> <!-- deprecated -->
<em> <em>
<xsl:apply-templates/> <xsl:apply-templates/>
</em> </em>
</xsl:template> </xsl:template>
<xsl:template match="sup"> <xsl:template match="sup">
<sup> <sup>
<xsl:apply-templates/> <xsl:apply-templates/>
</sup> </sup>
</xsl:template> </xsl:template>
<xsl:template match="sub"> <xsl:template match="sub">
<sub> <sub>
<xsl:apply-templates/> <xsl:apply-templates/>
</sub> </sub>
</xsl:template> </xsl:template>
<xsl:template match="smallCaps"> <xsl:template match="smallCaps">
<xsl:variable name="small" select="'abcdefghijklmnopqrstuvwxyz'"/> <xsl:variable name="small" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="caps" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <xsl:variable name="caps" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:value-of select="translate(text(), $small, $caps)"/> <xsl:value-of select="translate(text(), $small, $caps)"/>
</xsl:template> </xsl:template>
<xsl:template match="SideNote"> <xsl:template match="SideNote">
<br/> <br/>
<span class="required-prodnote">Side note</span> <hr/>
<xsl:apply-templates/> <span class="required-prodnote">Side note</span>
<br/> <br/>
<span class="optional-prodnote">End of side note</span> <xsl:apply-templates/>
<br/> <span class="optional-prodnote">End of side note</span>
</xsl:template> <hr/>
<xsl:template match="SideNote/Heading"> <br/>
<br/> </xsl:template>
<em> <xsl:template match="SideNote/Heading">
<xsl:apply-templates/> <br/>
</em> <em>
</xsl:template> <xsl:apply-templates/>
<xsl:template match="SideNoteParagraph"> </em>
<br/> </xsl:template>
<xsl:apply-templates/> <xsl:template match="SideNoteParagraph">
</xsl:template> <br/>
<xsl:template match="Footnote"> <xsl:apply-templates/>
<br/> </xsl:template>
<span class="required-prodnote">Footnote</span> <xsl:template match="Footnote">
<br/> <br/>
<xsl:apply-templates/> <hr/>
<br/> <span class="required-prodnote">Footnote</span>
<span class="optional-prodnote">End of footnote</span> <br/>
<br/> <xsl:apply-templates/>
</xsl:template> <br/>
<xsl:template match="InlineEquation"> <hr/>
<br/> <span class="optional-prodnote">End of footnote</span>
<xsl:apply-templates/> <br/>
</xsl:template> </xsl:template>
<xsl:template match="InlineEquation/Image"> <xsl:template match="InlineEquation">
<img> <br/>
<xsl:attribute name="src"> <xsl:apply-templates/>
<xsl:value-of select="./Image/@src"/> </xsl:template>
</xsl:attribute> <xsl:template match="InlineEquation/Image">
<xsl:attribute name="alt"> <img>
<xsl:value-of select="./Image/@alt"/> <xsl:attribute name="src">
</xsl:attribute> <xsl:value-of select="./Image/@src"/>
</img> </xsl:attribute>
</xsl:template> <xsl:attribute name="alt">
<xsl:template match="InlineEquation/Description"> <xsl:value-of select="./Image/@alt"/>
<value-of select="text()"/> </xsl:attribute>
<br/> </img>
</xsl:template> </xsl:template>
<xsl:template match="InlineEquation/Alternative"> <xsl:template match="InlineEquation/Description">
<value-of select="text()"/> <value-of select="text()"/>
<br/> <br/>
</xsl:template> </xsl:template>
<xsl:template match="InlineEquation/TeX | InlineEquation/MathML"/> <xsl:template match="InlineEquation/Alternative">
<xsl:template match="AuthorComment"> <value-of select="text()"/>
<!-- omit --> <br/>
<xsl:apply-templates/> </xsl:template>
</xsl:template> <xsl:template match="InlineEquation/TeX | InlineEquation/MathML"/>
<xsl:template match="EditorComment"> <xsl:template match="AuthorComment">
<!-- omit --> <!-- omit -->
</xsl:template> <xsl:apply-templates/>
</xsl:stylesheet> </xsl:template>
<xsl:template match="EditorComment">
<!-- omit -->
</xsl:template>
</xsl:stylesheet>

View File

@ -2,16 +2,20 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="apply-templates-lang"> <xsl:template name="apply-templates-lang">
<xsl:for-each select="@xml:lang"> <xsl:for-each select="@xml:lang">
<xsl:copy/> <xsl:if test="string-length(.) &gt; 0">
<xsl:copy/>
</xsl:if>
</xsl:for-each> </xsl:for-each>
<xsl:apply-templates/> <xsl:apply-templates/>
</xsl:template> </xsl:template>
<xsl:template match="language"> <xsl:template match="language">
<span> <xsl:if test="string-length(@val) &gt; 0">
<xsl:attribute name="xml:lang"> <span>
<xsl:value-of select="@val"/> <xsl:attribute name="xml:lang">
</xsl:attribute> <xsl:value-of select="@val"/>
<xsl:apply-templates/> </xsl:attribute>
</span> <xsl:apply-templates/>
</span>
</xsl:if>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View File

@ -103,20 +103,36 @@
<p> <p>
<span class="optional-prodnote">Figure</span> <span class="optional-prodnote">Figure</span>
</p> </p>
<p> <xsl:choose>
<img> <xsl:when test="string-length(./Image/@src) &gt; 0">
<xsl:attribute name="src"> <img>
<xsl:value-of select="./Image/@src"/> <xsl:attribute name="src">
</xsl:attribute> <xsl:value-of select="./Image/@src"/>
<xsl:attribute name="alt"> </xsl:attribute>
<xsl:value-of select="./Image/@alt"/> <xsl:attribute name="alt">
</xsl:attribute> <xsl:choose>
</img> <xsl:when test="string-length(./Image/@alt) &gt; 0">
</p> <xsl:value-of select="./Image/@alt"/>
</xsl:when>
<xsl:when test="string-length(Alternative) &gt; 0">
<xsl:value-of select="Alternative"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>no alternative text</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</img>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:apply-templates select="./Image/text() | ./Image/* "/>
</p>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="Caption"/> <xsl:apply-templates select="Caption"/>
<xsl:apply-templates select="Alternative"/>
<xsl:apply-templates select="Description"/> <xsl:apply-templates select="Description"/>
<xsl:apply-tempaltes select="SourceReference"/> <xsl:apply-templates select="SourceReference"/>
<p> <p>
<span class="optional-prodnote">End of figure</span> <span class="optional-prodnote">End of figure</span>
</p> </p>
@ -125,22 +141,39 @@
<p> <p>
<span class="optional-prodnote">Equation</span> <span class="optional-prodnote">Equation</span>
</p> </p>
<p> <xsl:choose>
<img> <xsl:when test="string-length(./Image/@src) &gt; 0">
<xsl:attribute name="src"> <img>
<xsl:value-of select="./Image/@src"/> <xsl:attribute name="src">
</xsl:attribute> <xsl:value-of select="./Image/@src"/>
<xsl:attribute name="alt"> </xsl:attribute>
<xsl:value-of select="./Image/@alt"/> <xsl:attribute name="alt">
</xsl:attribute> <xsl:choose>
</img> <xsl:when test="string-length(./Image/@alt) &gt; 0">
</p> <xsl:value-of select="./Image/@alt"/>
</xsl:when>
<xsl:when test="string-length(Alternative) &gt; 0">
<xsl:value-of select="Alternative"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>no alternative text</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</img>
</xsl:when>
<xsl:otherwise>
<p>
<xsl:apply-templates select="./Image/text() | ./Image/* "/>
</p>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="Label"/>
<xsl:apply-templates select="TeX"/> <xsl:apply-templates select="TeX"/>
<xsl:apply-templates select="MathML"/> <xsl:apply-templates select="MathML"/>
<xsl:apply-templates select="Caption"/> <xsl:apply-templates select="Caption"/>
<xsl:apply-templates select="Alternative"/>
<xsl:apply-templates select="Description"/> <xsl:apply-templates select="Description"/>
<xsl:apply-tempaltes select="SourceReference"/> <xsl:apply-templates select="SourceReference"/>
<span class="optional-prodnote">End of equation</span> <span class="optional-prodnote">End of equation</span>
</xsl:template> </xsl:template>
<xsl:template match="Equation/TeX"> <xsl:template match="Equation/TeX">

View File

@ -10,9 +10,11 @@
</xsl:template> </xsl:template>
<xsl:template match="UnitID"/> <xsl:template match="UnitID"/>
<xsl:template match="UnitTitle"> <xsl:template match="UnitTitle">
<h1> <xsl:if test="string-length(./text()) &gt; 0">
<xsl:call-template name="apply-templates-lang"/> <h1>
</h1> <xsl:call-template name="apply-templates-lang"/>
</h1>
</xsl:if>
</xsl:template> </xsl:template>
<xsl:template match="Unit/ByLine"> <xsl:template match="Unit/ByLine">
<p> <p>
@ -125,15 +127,19 @@
</xsl:template> </xsl:template>
<xsl:template match="MediaContent"> <xsl:template match="MediaContent">
<xsl:if test="@type = 'audio'"> <xsl:if test="@type = 'audio'">
<p><span class="required-prodnote">[Audio content]</span></p> <p>
<span class="required-prodnote">[Audio content]</span>
</p>
<p> <p>
<a><xsl:attribute name="href"><xsl:value-of select="@src"/>.mp3</xsl:attribute>MP3 file <a><xsl:attribute name="href"><xsl:value-of select="@src"/>.mp3</xsl:attribute>MP3 file
</a> </a>
</p> </p>
</xsl:if> </xsl:if>
<xsl:if test="@type = 'pdf'"> <xsl:if test="@type = 'pdf'">
<p><span class="required-prodnote">[PDF content]</span></p> <p>
<!--<p><a><xsl:attribute name="href"><xsl:value-of select="@src"/>.pdf</xsl:attribute></a></p>--> <span class="required-prodnote">[PDF content]</span>
</p>
<!--<p><a><xsl:attribute name="href"><xsl:value-of select="@src"/>.pdf</xsl:attribute></a></p>-->
</xsl:if> </xsl:if>
<xsl:call-template name="apply-templates-lang"/> <xsl:call-template name="apply-templates-lang"/>
<p> <p>
@ -162,22 +168,32 @@
</xsl:template> </xsl:template>
<xsl:template match="Caption"> <xsl:template match="Caption">
<p> <p>
<xsl:call-template name="apply-templates-lang"/> <span class="caption">
<xsl:call-template name="apply-templates-lang"/>
</span>
</p> </p>
</xsl:template> </xsl:template>
<xsl:template match="Alternative"> <xsl:template match="Alternative">
<p> <p>
<xsl:if test="string-length(.) &gt; 0">
<span class="optional-prodnote"><strong>Alternative</strong>: </span>
</xsl:if>
<xsl:call-template name="apply-templates-lang"/> <xsl:call-template name="apply-templates-lang"/>
</p> </p>
</xsl:template> </xsl:template>
<xsl:template match="Description"> <xsl:template match="Description">
<p> <p>
<xsl:if test="string-length(.) &gt; 0">
<span class="optional-prodnote"><strong>Description</strong>: </span>
</xsl:if>
<xsl:call-template name="apply-templates-lang"/> <xsl:call-template name="apply-templates-lang"/>
</p> </p>
</xsl:template> </xsl:template>
<xsl:template match="Label"> <xsl:template match="Label">
<p> <p>
<xsl:call-template name="apply-templates-lang"/> <strong>
<xsl:call-template name="apply-templates-lang"/>
</strong>
</p> </p>
</xsl:template> </xsl:template>
<xsl:template match="Table"> <xsl:template match="Table">