| 1 |
<?xml version="1.0" encoding="ASCII"?><!--This file was created automatically by html2xhtml--><!--from the HTML stylesheets.--><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="http://docbook.org/ns/docbook" xmlns:its="http://www.w3.org/2005/11/its" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="its d" version="1.0"> |
| 2 |
|
| 3 |
<!-- ******************************************************************** |
| 4 |
|
| 5 |
This file is part of the XSL DocBook Stylesheet distribution. |
| 6 |
See ../README or http://cdn.docbook.org/release/xsl/current/ for |
| 7 |
copyright and other information. |
| 8 |
|
| 9 |
Templates in this stylesheet convert ITS 2.0 markup |
| 10 |
http://www.w3.org/TR/its20/ into corresponding HTML5 attributes |
| 11 |
(prefixed with its-*). |
| 12 |
|
| 13 |
******************************************************************** --> |
| 14 |
|
| 15 |
<!-- List of recognized ITS attributes --> |
| 16 |
<xsl:variable name="its-attrs"> its-allowed-characters its-annotators-ref its-line-break-type its-loc-note its-loc-note-ref its-loc-note-type its-loc-quality-issue-comment its-loc-quality-issue-enabled its-loc-quality-issue-profile-ref its-loc-quality-issue-severity its-loc-quality-issue-type its-loc-quality-issues-ref its-loc-quality-rating-profile-ref its-loc-quality-rating-score its-loc-quality-rating-score-threshold its-loc-quality-rating-vote its-loc-quality-rating-vote-threshold its-locale-filter-list its-locale-filter-type its-mt-confidence its-org its-org-ref its-person its-person-ref its-prov-ref its-provenance-records-ref its-rev-org its-rev-org-ref its-rev-person its-rev-person-ref its-rev-tool its-rev-tool-ref its-storage-encoding its-storage-size its-ta-class-ref its-ta-confidence its-ta-ident its-ta-ident-ref its-ta-source its-term its-term-confidence its-term-info-ref its-tool its-tool-ref its-within-text </xsl:variable> |
| 17 |
|
| 18 |
<xsl:template name="its.attributes"> |
| 19 |
<xsl:param name="inherit" select="0"/> |
| 20 |
<xsl:apply-templates select="." mode="its.attributes"> |
| 21 |
<xsl:with-param name="inherit" select="$inherit"/> |
| 22 |
</xsl:apply-templates> |
| 23 |
</xsl:template> |
| 24 |
|
| 25 |
<xsl:template match="*" mode="its.attributes"> |
| 26 |
<xsl:param name="inherit" select="0"/> |
| 27 |
|
| 28 |
<xsl:choose> |
| 29 |
<!-- Handle inheritance; especially necessary for chunking --> |
| 30 |
<xsl:when test="$inherit = 1"> |
| 31 |
<xsl:variable name="attrs" select="ancestor-or-self::*/@*[namespace-uri() = 'http://www.w3.org/2005/11/its']"/> |
| 32 |
<xsl:for-each select="$attrs"> |
| 33 |
<xsl:variable name="name" select="local-name(.)"/> |
| 34 |
<xsl:if test="not(..//*/@*[local-name(.) = $name and (count(. | $attrs) = 1)])"> |
| 35 |
<xsl:apply-templates select="."/> |
| 36 |
</xsl:if> |
| 37 |
</xsl:for-each> |
| 38 |
</xsl:when> |
| 39 |
<xsl:otherwise> |
| 40 |
<xsl:apply-templates select="@*[namespace-uri() = 'http://www.w3.org/2005/11/its']"/> |
| 41 |
</xsl:otherwise> |
| 42 |
</xsl:choose> |
| 43 |
</xsl:template> |
| 44 |
|
| 45 |
<!-- translate attribute is special in HTML --> |
| 46 |
<xsl:template match="@its:translate"> |
| 47 |
<xsl:attribute name="translate"> |
| 48 |
<xsl:value-of select="."/> |
| 49 |
</xsl:attribute> |
| 50 |
</xsl:template> |
| 51 |
|
| 52 |
<xsl:template match="@its:*"> |
| 53 |
<xsl:variable name="attr"> |
| 54 |
<xsl:call-template name="its-html-attribute-name"> |
| 55 |
<xsl:with-param name="name" select="local-name(.)"/> |
| 56 |
</xsl:call-template> |
| 57 |
</xsl:variable> |
| 58 |
|
| 59 |
<xsl:choose> |
| 60 |
<xsl:when test="contains($its-attrs, concat(' ', $attr, ' '))"> |
| 61 |
<xsl:attribute name="{$attr}"> |
| 62 |
<xsl:value-of select="."/> |
| 63 |
</xsl:attribute> |
| 64 |
</xsl:when> |
| 65 |
<xsl:otherwise> |
| 66 |
<xsl:message>Attribute <xsl:value-of select="name(.)"/> is not recognized as ITS attribute. Ignoring.</xsl:message> |
| 67 |
</xsl:otherwise> |
| 68 |
</xsl:choose> |
| 69 |
</xsl:template> |
| 70 |
|
| 71 |
<xsl:template name="its-html-attribute-name"> |
| 72 |
<xsl:param name="name"/> |
| 73 |
|
| 74 |
<xsl:text>its-</xsl:text> |
| 75 |
<xsl:call-template name="its-camel-case-to-dashes"> |
| 76 |
<xsl:with-param name="text" select="$name"/> |
| 77 |
</xsl:call-template> |
| 78 |
</xsl:template> |
| 79 |
|
| 80 |
<xsl:template name="its-camel-case-to-dashes"> |
| 81 |
<xsl:param name="text"/> |
| 82 |
|
| 83 |
<xsl:variable name="first" select="substring($text, 1, 1)"/> |
| 84 |
<xsl:variable name="rest" select="substring($text, 2)"/> |
| 85 |
|
| 86 |
<xsl:choose> |
| 87 |
<xsl:when test="$first != translate($first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"> |
| 88 |
<xsl:value-of select="'-'"/> |
| 89 |
<xsl:value-of select="translate($first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/> |
| 90 |
</xsl:when> |
| 91 |
<xsl:otherwise> |
| 92 |
<xsl:value-of select="$first"/> |
| 93 |
</xsl:otherwise> |
| 94 |
</xsl:choose> |
| 95 |
|
| 96 |
<xsl:if test="$rest != ''"> |
| 97 |
<xsl:call-template name="its-camel-case-to-dashes"> |
| 98 |
<xsl:with-param name="text" select="$rest"/> |
| 99 |
</xsl:call-template> |
| 100 |
</xsl:if> |
| 101 |
</xsl:template> |
| 102 |
|
| 103 |
</xsl:stylesheet> |