]> granicus.if.org Git - docbook-dsssl/commitdiff
Added basic support for ITS 2.0 markup. It gets propagated into HTML
authorJirka Kosek <jirka@kosek.cz>
Wed, 8 May 2013 12:56:32 +0000 (12:56 +0000)
committerJirka Kosek <jirka@kosek.cz>
Wed, 8 May 2013 12:56:32 +0000 (12:56 +0000)
For more info about ITS see http://www.w3.org/TR/its20/

xsl/html/docbook.xsl
xsl/html/html.xsl
xsl/html/its.xsl [new file with mode: 0644]

index 5c631d2eaff1516b0d911f8f3b81f5f4c0f6bc0d..0bb4647b2d71155ec2110c6e2f7269468a3d936e 100644 (file)
@@ -51,6 +51,7 @@
 <xsl:include href="inline.xsl"/>
 <xsl:include href="footnote.xsl"/>
 <xsl:include href="html.xsl"/>
+<xsl:include href="its.xsl"/>
 <xsl:include href="info.xsl"/>
 <xsl:include href="keywords.xsl"/>
 <xsl:include href="division.xsl"/>
index 54a940472e39ea9aa3ccdb7158d0ad7f01d45ca5..65710c4584becfb18b5618289bb9b508e950fc39 100644 (file)
   <xsl:apply-templates select="." mode="class.attribute">
     <xsl:with-param name="class" select="$class"/>
   </xsl:apply-templates>
+  <xsl:call-template name="its.attributes">
+    <xsl:with-param name="inherit" select="$inherit"/>
+  </xsl:call-template>
 </xsl:template>
 
 <!-- Apply common attributes not including class -->
 <xsl:template match="*" mode="locale.html.attributes">
   <xsl:call-template name="generate.html.lang"/>
   <xsl:call-template name="dir"/>
+  <xsl:call-template name="its.attributes"/>
 </xsl:template>
 
 <!-- Pass through any lang attributes -->
diff --git a/xsl/html/its.xsl b/xsl/html/its.xsl
new file mode 100644 (file)
index 0000000..4f507d6
--- /dev/null
@@ -0,0 +1,109 @@
+<?xml version='1.0'?>\r
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
+               xmlns:its="http://www.w3.org/2005/11/its"\r
+               exclude-result-prefixes="its"\r
+                version='1.0'>\r
+\r
+<!-- ********************************************************************\r
+     $Id: html.xsl 9306 2012-04-28 03:49:00Z bobstayton $\r
+     ********************************************************************\r
+\r
+     This file is part of the XSL DocBook Stylesheet distribution.\r
+     See ../README or http://docbook.sf.net/release/xsl/current/ for\r
+     copyright and other information.\r
+\r
+     Templates in this stylesheet convert ITS 2.0 markup\r
+     http://www.w3.org/TR/its20/ into corresponding HTML5 attributes\r
+     (prefixed with its-*).\r
+\r
+     ******************************************************************** -->\r
+\r
+<!-- List of recognized ITS attributes -->\r
+<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>\r
+\r
+<xsl:template name="its.attributes">\r
+  <xsl:param name="inherit" select="0"/>\r
+  <xsl:apply-templates select="." mode="its.attributes">\r
+    <xsl:with-param name="inherit" select="$inherit"/>\r
+  </xsl:apply-templates>\r
+</xsl:template>\r
+\r
+<xsl:template match="*" mode="its.attributes">\r
+  <xsl:param name="inherit" select="0"/>\r
+\r
+  <xsl:choose>\r
+    <!-- Handle inheritance; especially necessary for chunking -->\r
+    <xsl:when test="$inherit = 1">\r
+      <xsl:variable name="attrs" select="ancestor-or-self::*/@its:*"/>\r
+      <xsl:for-each select="$attrs">\r
+       <xsl:variable name="name" select="local-name(.)"/>\r
+       <xsl:if test="not(..//*/@*[local-name(.) = $name and (count(. | $attrs) = 1)])">\r
+         <xsl:apply-templates select="."/>\r
+       </xsl:if>\r
+      </xsl:for-each>\r
+    </xsl:when>\r
+    <xsl:otherwise>\r
+      <xsl:apply-templates select="@its:*"/>\r
+    </xsl:otherwise>\r
+  </xsl:choose>\r
+</xsl:template>\r
+\r
+<!-- translate attribute is special in HTML -->\r
+<xsl:template match="@its:translate">\r
+  <xsl:attribute name="translate">\r
+    <xsl:value-of select="."/>\r
+  </xsl:attribute>\r
+</xsl:template>\r
+\r
+<xsl:template match="@its:*">\r
+  <xsl:variable name="attr">\r
+    <xsl:call-template name="its-html-attribute-name">\r
+      <xsl:with-param name="name" select="local-name(.)"/>\r
+    </xsl:call-template>\r
+  </xsl:variable>\r
+\r
+  <xsl:choose>\r
+    <xsl:when test="contains($its-attrs, concat(' ', $attr, ' '))">\r
+      <xsl:attribute name="{$attr}">\r
+       <xsl:value-of select="."/>\r
+      </xsl:attribute>\r
+    </xsl:when>\r
+    <xsl:otherwise>\r
+      <xsl:message>Attribute <xsl:value-of select="name(.)"/> is not recognized as ITS attribute. Ignoring.</xsl:message>\r
+    </xsl:otherwise>\r
+  </xsl:choose>\r
+</xsl:template>\r
+\r
+<xsl:template name="its-html-attribute-name">\r
+  <xsl:param name="name"/>\r
+\r
+  <xsl:text>its-</xsl:text>\r
+  <xsl:call-template name="its-camel-case-to-dashes">\r
+    <xsl:with-param name="text" select="$name"/>\r
+  </xsl:call-template>\r
+</xsl:template>\r
+\r
+<xsl:template name="its-camel-case-to-dashes">\r
+  <xsl:param name="text"/>\r
+\r
+  <xsl:variable name="first" select="substring($text, 1, 1)"/>\r
+  <xsl:variable name="rest" select="substring($text, 2)"/>\r
+\r
+  <xsl:choose>\r
+    <xsl:when test="$first != translate($first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')">\r
+      <xsl:value-of select="'-'"/>\r
+      <xsl:value-of select="translate($first, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>\r
+    </xsl:when>\r
+    <xsl:otherwise>\r
+      <xsl:value-of select="$first"/>\r
+    </xsl:otherwise>\r
+  </xsl:choose>\r
+  \r
+  <xsl:if test="$rest != ''">\r
+  <xsl:call-template name="its-camel-case-to-dashes">\r
+      <xsl:with-param name="text" select="$rest"/>\r
+    </xsl:call-template>\r
+  </xsl:if>\r
+</xsl:template>\r
+\r
+</xsl:stylesheet>\r