1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output
doctype-public="-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
doctype-system="http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd"
cdata-section-elements="book"
indent="yes"
encoding="UTF-8"
/>
<!-- split an element with comma-separated text into multiple elements -->
<xsl:template name="str.split">
<xsl:param name="text"/>
<xsl:param name="elem"/>
<xsl:param name="sep" />
<xsl:if test="string-length($text) > 0">
<xsl:variable name="next" select="substring-before(concat($text,$sep), $sep)"/>
<xsl:element name="{$elem}">
<xsl:value-of select="normalize-space($next)"/>
</xsl:element>
<xsl:call-template name="str.split">
<xsl:with-param name="text" select="substring-after($text, $sep)"/>
<xsl:with-param name="elem" select="$elem"/>
<xsl:with-param name="sep" select="$sep"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- identity transform, for nodes that do not match anything else -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="refpurpose">
<refpurpose>
<xsl:value-of select="normalize-space(.)"/>
</refpurpose>
</xsl:template>
<xsl:template match="refname">
<refname>
<xsl:value-of select="normalize-space(.)"/>
</refname>
</xsl:template>
<xsl:template match="refentrytitle">
<refentrytitle>
<xsl:value-of select="normalize-space(.)"/>
</refentrytitle>
</xsl:template>
<!-- keywords should be individual keywords, not a comma-separated list -->
<xsl:template match="keyword">
<xsl:call-template name="str.split">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="elem" select="'keyword'"/>
<xsl:with-param name="sep" select="', '"/>
</xsl:call-template>
</xsl:template>
<!-- TODO the same treatment should be reserved to refentrytitle -->
<!-- The khronos documents are marked to be in man section 3, but this
causes conflicts with the C standard library pages (e.g. cbrt).
Append 'cl' to the OpenCL sections to resolve the conflict. -->
<xsl:template match="/refentry/refmeta/manvolnum">
<manvolnum>
<xsl:value-of select="concat(normalize-space(.), 'clc')"/>
</manvolnum>
</xsl:template>
<!-- copyright/holder should only be the copyright holder. The rest of the legal notice should
go into a legalnotice element inside refentryinfo -->
<xsl:template match="copyright/holder">
<holder>
<xsl:value-of select="concat(substring-before(normalize-space(), '. '), '.')"/>
</holder>
</xsl:template>
<!-- The copyright info should be inside refentryinfo, not inside refmeta/refmiscinfo -->
<xsl:template match="/refentry/refentryinfo">
<xsl:copy>
<!-- copy existing stuff in refentryinfo -->
<xsl:apply-templates select="@*|node()"/>
<!-- copy and fix the copyright; note that this can't all be done from the
copyright/holder template because the legalnotice must go out -->
<xsl:variable name="wrongpath" select="../refmeta/refmiscinfo/copyright"/>
<!-- extract copyright/holder text -->
<xsl:variable name="cprt" select="normalize-space($wrongpath)"/>
<xsl:apply-templates select="$wrongpath"/>
<xsl:element name="legalnotice">
<!-- get the text after the first full-stop in the former
copyright/holder text -->
<xsl:value-of select="substring-after($cprt, '. ')"/>
</xsl:element>
<!-- while we're at it, add the orgname that should go here too -->
<xsl:element name="orgname">
<xsl:attribute name="class">consortium</xsl:attribute>
<xsl:text>The Khronos Group</xsl:text>
</xsl:element>
</xsl:copy>
</xsl:template>
<!-- delete the copyright from original position, as well as the now-empty refmiscinfo
TODO: check that refmiscinfo is actually empty.
This is simply done by NOT copying it to the output file -->
<xsl:template match="/refentry/refmeta/refmiscinfo"/>
<!-- now we recreate refmiscinfo to read "OpenCL Manual" -->
<xsl:template match="/refentry/refmeta">
<xsl:copy>
<!-- again, copy existing children -->
<xsl:apply-templates select="@*|node()"/>
<!-- and add our new refmiscinfo now -->
<xsl:element name="refmiscinfo">
<xsl:attribute name="class">manual</xsl:attribute>
<xsl:text>OpenCL Manual</xsl:text>
</xsl:element>
</xsl:copy>
</xsl:template>
<!-- links are used throughout the OpenCL man pages to cross-reference enums and data types.
For the manpages production, we replace them with their textual content -->
<!-- TODO: we might want to automatically add these to the "see also" section" -->
<xsl:template match="link">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<!-- paramdefs have no space after them, and the * is inside the parameter,
so we manipulate them to add a space, and a * if necessary;
parameter elements are stripped of the leading * -->
<xsl:template match="paramdef/parameter/text()[starts-with(.,'*')]">
<xsl:value-of select="substring-after(., '*')"/>
</xsl:template>
<xsl:template match="paramdef/parameter">
<xsl:text> </xsl:text>
<xsl:if test="starts-with(text(), '*')">
<xsl:text>*</xsl:text>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--
section manipulation
-->
<!-- 'specification' section: skip the image. -->
<xsl:template match="refsect1[@id='specification']//imageobject"/>
<!-- turn olinks into ulinks with an url attribute that renders to page XX, section Title,
using data looked up from the section-to-page.xml table -->
<xsl:key name='specref' match='section' use='@id'/>
<xsl:template match="olink">
<xsl:variable name="secref" select="@uri"/>
<xsl:element name="ulink">
<xsl:attribute name="url">
<!-- TODO there must be a way to collect both in one go -->
<xsl:text>page </xsl:text>
<xsl:for-each select="document('section-to-page.xml')">
<xsl:value-of select="key('specref', $secref)/page"/>
</xsl:for-each>
<xsl:text>, section </xsl:text>
<xsl:for-each select="document('section-to-page.xml')">
<xsl:value-of select="key('specref', $secref)/title"/>
</xsl:for-each>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- don't copy 'copyright' section, it's automatically created from the legal notice -->
<xsl:template match="refsect3[@id='Copyright']"/>
<!-- Also see is more usually written See also in man pages-->
<xsl:template match="refsect1[@id='seealso']/title">
<title>See also</title>
</xsl:template>
</xsl:stylesheet>
|