Debian Codegraph @

docbook-xsl-ns/html/its.xsl

raw symbols SCIP
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:d="http://docbook.org/ns/docbook"
4 xmlns:its="http://www.w3.org/2005/11/its"
5 exclude-result-prefixes="its d"
6 version='1.0'>
7
8 <!-- ********************************************************************
9
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://cdn.docbook.org/release/xsl/current/ for
12 copyright and other information.
13
14 Templates in this stylesheet convert ITS 2.0 markup
15 http://www.w3.org/TR/its20/ into corresponding HTML5 attributes
16 (prefixed with its-*).
17
18 ******************************************************************** -->
19
20 <!-- List of recognized ITS attributes -->
21 <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>
22
23 <xsl:template name="its.attributes">
24 <xsl:param name="inherit" select="0"/>
25 <xsl:apply-templates select="." mode="its.attributes">
26 <xsl:with-param name="inherit" select="$inherit"/>
27 </xsl:apply-templates>
28 </xsl:template>
29
30 <xsl:template match="*" mode="its.attributes">
31 <xsl:param name="inherit" select="0"/>
32
33 <xsl:choose>
34 <!-- Handle inheritance; especially necessary for chunking -->
35 <xsl:when test="$inherit = 1">
36 <xsl:variable name="attrs" select="ancestor-or-self::*/@*[namespace-uri() = 'http://www.w3.org/2005/11/its']"/>
37 <xsl:for-each select="$attrs">
38 <xsl:variable name="name" select="local-name(.)"/>
39 <xsl:if test="not(..//*/@*[local-name(.) = $name and (count(. | $attrs) = 1)])">
40 <xsl:apply-templates select="."/>
41 </xsl:if>
42 </xsl:for-each>
43 </xsl:when>
44 <xsl:otherwise>
45 <xsl:apply-templates select="@*[namespace-uri() = 'http://www.w3.org/2005/11/its']"/>
46 </xsl:otherwise>
47 </xsl:choose>
48 </xsl:template>
49
50 <!-- translate attribute is special in HTML -->
51 <xsl:template match="@its:translate">
52 <xsl:attribute name="translate">
53 <xsl:value-of select="."/>
54 </xsl:attribute>
55 </xsl:template>
56
57 <xsl:template match="@its:*">
58 <xsl:variable name="attr">
59 <xsl:call-template name="its-html-attribute-name">
60 <xsl:with-param name="name" select="local-name(.)"/>
61 </xsl:call-template>
62 </xsl:variable>
63
64 <xsl:choose>
65 <xsl:when test="contains($its-attrs, concat(' ', $attr, ' '))">
66 <xsl:attribute name="{$attr}">
67 <xsl:value-of select="."/>
68 </xsl:attribute>
69 </xsl:when>
70 <xsl:otherwise>
71 <xsl:message>Attribute <xsl:value-of select="name(.)"/> is not recognized as ITS attribute. Ignoring.</xsl:message>
72 </xsl:otherwise>
73 </xsl:choose>
74 </xsl:template>
75
76 <xsl:template name="its-html-attribute-name">
77 <xsl:param name="name"/>
78
79 <xsl:text>its-</xsl:text>
80 <xsl:call-template name="its-camel-case-to-dashes">
81 <xsl:with-param name="text" select="$name"/>
82 </xsl:call-template>
83 </xsl:template>
84
85 <xsl:template name="its-camel-case-to-dashes">
86 <xsl:param name="text"/>
87
88 <xsl:variable name="first" select="substring($text, 1, 1)"/>
89 <xsl:variable name="rest" select="substring($text, 2)"/>
90
91 <xsl:choose>
92 <xsl:when test="$first != translate($first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')">
93 <xsl:value-of select="'-'"/>
94 <xsl:value-of select="translate($first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
95 </xsl:when>
96 <xsl:otherwise>
97 <xsl:value-of select="$first"/>
98 </xsl:otherwise>
99 </xsl:choose>
100
101 <xsl:if test="$rest != ''">
102 <xsl:call-template name="its-camel-case-to-dashes">
103 <xsl:with-param name="text" select="$rest"/>
104 </xsl:call-template>
105 </xsl:if>
106 </xsl:template>
107
108 </xsl:stylesheet>