| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" |
| 3 |
xmlns:func="http://exslt.org/functions" |
| 4 |
xmlns:exslt="http://exslt.org/common" |
| 5 |
xmlns:date="http://exslt.org/dates-and-times" |
| 6 |
xmlns:str="http://exslt.org/strings" |
| 7 |
xmlns:dyn="http://exslt.org/dynamic" |
| 8 |
extension-element-prefixes="exslt func date str dyn"> |
| 9 |
|
| 10 |
<!-- Go through doc, parse tests & includes to build |
| 11 |
result doc structure with all chapters/sections/bodies --> |
| 12 |
|
| 13 |
<xsl:variable name="doc-struct" xmlns=""> |
| 14 |
<xsl:call-template name="build-doc-struct"> |
| 15 |
<xsl:with-param name="doc" select="/"/> |
| 16 |
</xsl:call-template> |
| 17 |
</xsl:variable> |
| 18 |
|
| 19 |
<xsl:template name="build-doc-struct" xmlns=""> |
| 20 |
<xsl:param name="doc"/> |
| 21 |
<doc-struct> |
| 22 |
<xsl:attribute name="type"><xsl:value-of select="name($doc/*[1])"/></xsl:attribute> |
| 23 |
<file><xsl:value-of select="$link"/></file> |
| 24 |
<xsl:if test="$doc/*[1]/date"> |
| 25 |
<date><xsl:value-of select="$doc/*[1]/date"/></date> |
| 26 |
</xsl:if> |
| 27 |
<xsl:if test="$doc/*[1]/version"> |
| 28 |
<version><xsl:value-of select="$doc/*[1]/version"/></version> |
| 29 |
</xsl:if> |
| 30 |
<xsl:choose> |
| 31 |
<xsl:when test="$doc/book"> |
| 32 |
<xsl:for-each select="$doc/book/part"> |
| 33 |
<xsl:variable name="curpart" select="position()"/> |
| 34 |
<bookpart pos="{$curpart}"> |
| 35 |
<xsl:for-each select="chapter"> |
| 36 |
<xsl:variable name="curchap" select="position()"/> |
| 37 |
<bookchap pos="{$curchap}"> |
| 38 |
<xsl:if test="$full='1' or ($curpart=$part and $curchap=$chap)"> |
| 39 |
<xsl:variable name="inc" select="document(include/@href)"/> |
| 40 |
<file><xsl:value-of select="include/@href"/></file> |
| 41 |
<xsl:if test="$inc/sections/date"> |
| 42 |
<date><xsl:value-of select="$inc/sections/date"/></date> |
| 43 |
</xsl:if> |
| 44 |
<xsl:if test="$inc/sections/version"> |
| 45 |
<version><xsl:value-of select="$inc/sections/version"/></version> |
| 46 |
</xsl:if> |
| 47 |
<xsl:for-each select="$inc/sections/section[not(@test) or dyn:evaluate(@test)]"> |
| 48 |
<xsl:call-template name="doc-struct-chapters"> |
| 49 |
<xsl:with-param name="chapter" select="."/> |
| 50 |
</xsl:call-template> |
| 51 |
</xsl:for-each> |
| 52 |
</xsl:if> |
| 53 |
</bookchap> |
| 54 |
</xsl:for-each> |
| 55 |
</bookpart> |
| 56 |
</xsl:for-each> |
| 57 |
</xsl:when> |
| 58 |
<xsl:otherwise> |
| 59 |
<xsl:for-each select="$doc//faqindex | $doc/*[1]/chapter[not(@test) or dyn:evaluate(@test)]"> |
| 60 |
<xsl:call-template name="doc-struct-chapters"> |
| 61 |
<xsl:with-param name="chapter" select="."/> |
| 62 |
</xsl:call-template> |
| 63 |
</xsl:for-each> |
| 64 |
</xsl:otherwise> |
| 65 |
</xsl:choose> |
| 66 |
</doc-struct> |
| 67 |
</xsl:template> |
| 68 |
|
| 69 |
<xsl:template name="doc-struct-chapters" xmlns=""> |
| 70 |
<xsl:param name="chapter"/> |
| 71 |
<xsl:choose> |
| 72 |
<xsl:when test="$chapter/include"> |
| 73 |
<xsl:variable name="inc" select="document($chapter/include/@href)"/> |
| 74 |
<file><xsl:value-of select="$chapter/include/@href"/></file> |
| 75 |
<xsl:if test="$inc//date"> |
| 76 |
<date><xsl:value-of select="$inc//date"/></date> |
| 77 |
</xsl:if> |
| 78 |
<xsl:if test="$inc//version"> |
| 79 |
<version><xsl:value-of select="$inc//version"/></version> |
| 80 |
</xsl:if> |
| 81 |
<xsl:for-each select="$inc//chapter[not(@test) or dyn:evaluate(@test)]"> |
| 82 |
<xsl:call-template name="doc-struct-chapters"> |
| 83 |
<xsl:with-param name="chapter" select="."/> |
| 84 |
</xsl:call-template> |
| 85 |
</xsl:for-each> |
| 86 |
</xsl:when> |
| 87 |
<xsl:otherwise> |
| 88 |
<chapter uid="{generate-id($chapter)}" title="{$chapter/title}"> |
| 89 |
<xsl:if test="$chapter/@id"><xsl:attribute name="id"><xsl:value-of select="$chapter/@id"/></xsl:attribute></xsl:if> |
| 90 |
<xsl:choose> |
| 91 |
<xsl:when test="body"> |
| 92 |
<!-- Handbook section without subsection(s), bodies only --> |
| 93 |
<xsl:for-each select="$chapter/body[not(@test) or dyn:evaluate(@test)]"> |
| 94 |
<xsl:call-template name="doc-struct-bodies"> |
| 95 |
<xsl:with-param name="body" select="."/> |
| 96 |
</xsl:call-template> |
| 97 |
</xsl:for-each> |
| 98 |
</xsl:when> |
| 99 |
<xsl:otherwise> |
| 100 |
<xsl:for-each select="$chapter/section[not(@test) or dyn:evaluate(@test)] | $chapter/subsection[not(@test) or dyn:evaluate(@test)]"> |
| 101 |
<xsl:call-template name="doc-struct-sections"> |
| 102 |
<xsl:with-param name="section" select="."/> |
| 103 |
</xsl:call-template> |
| 104 |
</xsl:for-each> |
| 105 |
</xsl:otherwise> |
| 106 |
</xsl:choose> |
| 107 |
</chapter> |
| 108 |
</xsl:otherwise> |
| 109 |
</xsl:choose> |
| 110 |
</xsl:template> |
| 111 |
|
| 112 |
<xsl:template name="doc-struct-sections" xmlns=""> |
| 113 |
<xsl:param name="section"/> |
| 114 |
<xsl:choose> |
| 115 |
<xsl:when test="$section/include"> |
| 116 |
<xsl:variable name="inc" select="document($section/include/@href)"/> |
| 117 |
<file><xsl:value-of select="$section/include/@href"/></file> |
| 118 |
<xsl:if test="$inc//date"> |
| 119 |
<date><xsl:value-of select="$inc//date"/></date> |
| 120 |
</xsl:if> |
| 121 |
<xsl:if test="$inc//version"> |
| 122 |
<version><xsl:value-of select="$inc//version"/></version> |
| 123 |
</xsl:if> |
| 124 |
<xsl:for-each select="$inc//section[not(@test) or dyn:evaluate(@test)]"> |
| 125 |
<xsl:call-template name="doc-struct-sections"> |
| 126 |
<xsl:with-param name="section" select="."/> |
| 127 |
</xsl:call-template> |
| 128 |
</xsl:for-each> |
| 129 |
</xsl:when> |
| 130 |
<xsl:when test="$section/body"> |
| 131 |
<section uid="{generate-id($section)}" title="{$section/title}"> |
| 132 |
<xsl:if test="$section/@id"><xsl:attribute name="id"><xsl:value-of select="$section/@id"/></xsl:attribute></xsl:if> |
| 133 |
<xsl:for-each select="$section/body[not(@test) or dyn:evaluate(@test)]"> |
| 134 |
<xsl:call-template name="doc-struct-bodies"> |
| 135 |
<xsl:with-param name="body" select="."/> |
| 136 |
</xsl:call-template> |
| 137 |
</xsl:for-each> |
| 138 |
</section> |
| 139 |
</xsl:when> |
| 140 |
<xsl:otherwise> |
| 141 |
<section uid="{generate-id($section)}" title="{$section/title}"> |
| 142 |
<!-- bodyless section in old invalid files --> |
| 143 |
<xsl:call-template name="doc-struct-bodies"> |
| 144 |
<xsl:with-param name="body" select="$section"/> |
| 145 |
</xsl:call-template> |
| 146 |
</section> |
| 147 |
</xsl:otherwise> |
| 148 |
</xsl:choose> |
| 149 |
</xsl:template> |
| 150 |
|
| 151 |
<xsl:template name="doc-struct-bodies" xmlns=""> |
| 152 |
<xsl:param name="body"/> |
| 153 |
<xsl:choose> |
| 154 |
<xsl:when test="$body/include"> |
| 155 |
<xsl:variable name="inc" select="document($body/include/@href)"/> |
| 156 |
<file><xsl:value-of select="$body/include/@href"/></file> |
| 157 |
<xsl:if test="$inc//date"> |
| 158 |
<date><xsl:value-of select="$inc//date"/></date> |
| 159 |
</xsl:if> |
| 160 |
<xsl:if test="$inc//version"> |
| 161 |
<version><xsl:value-of select="$inc//version"/></version> |
| 162 |
</xsl:if> |
| 163 |
<xsl:for-each select="$inc//body[not(@test) or dyn:evaluate(@test)]"> |
| 164 |
<xsl:call-template name="doc-struct-bodies"> |
| 165 |
<xsl:with-param name="body" select="."/> |
| 166 |
</xsl:call-template> |
| 167 |
</xsl:for-each> |
| 168 |
</xsl:when> |
| 169 |
<xsl:otherwise> |
| 170 |
<body uid="{generate-id($body)}"> |
| 171 |
|
| 172 |
<xsl:for-each select="$body/pre[not(@test) or dyn:evaluate(@test)] | $body/figure[not(@test) or dyn:evaluate(@test)]"> |
| 173 |
<xsl:element name="{name()}"> |
| 174 |
<xsl:attribute name="uid"> |
| 175 |
<xsl:value-of select="generate-id(.)"/> |
| 176 |
</xsl:attribute> |
| 177 |
</xsl:element> |
| 178 |
</xsl:for-each> |
| 179 |
|
| 180 |
</body> |
| 181 |
</xsl:otherwise> |
| 182 |
</xsl:choose> |
| 183 |
</xsl:template> |
| 184 |
|
| 185 |
</xsl:stylesheet> |