topicpullImpl.xsl 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- This file is part of the DITA Open Toolkit project hosted on
  3. Sourceforge.net. See the accompanying license.txt file for
  4. applicable licenses.-->
  5. <!-- (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved. -->
  6. <!--
  7. Fixes: add "-" to start of class attribute on generated elements (<linktext>, <desc>)
  8. links to elements inside abstract do not retrieve text
  9. Get link text for <link> elements that include <desc> but no link text
  10. Get link text for <xref> elements that include <desc> but no link text
  11. Get short description for <xref> elements that contain link text but no <desc>
  12. Fig and table numbering is now specialization aware
  13. XREF to dlentry looked for <dlterm>, should be <dt>
  14. No space between "Figure" and number in "Figure 1" reference
  15. No space between "Table" and number in "Table 1" reference
  16. Reference to table without @type used a title instead of Table N; now uses Table N to
  17. be consistent with typed reference and with figures
  18. Function to determine class had collapsed <xsl:text> </xsl:text> into <xsl:text/>,
  19. this caused the previous bug with tables
  20. Wrapping an </xsl:otherwise> to a newline added many spaces to '#none#' in some cases;
  21. resulted in type attributes getting set to "#none#&#xA; &#xA; "
  22. Hungarian references to figure and table should use Hungarian rules
  23. draft-comment and required-cleanup were pulled in to link text and hover help
  24. Shortdesc fixes:
  25. - If an element within a topic is the target, only look at that element for a desc (not the topic)
  26. - If a file has many topics, do not pull every shortdesc when targeting a topic
  27. - If a target topic uses abstract, add a space between shortdesc's in the abstract
  28. - If the target topic does not have a shortdesc, do not fall back to shortdesc from another topic
  29. -->
  30. <!-- Refactoring completed March and April 2007. The code now contains
  31. numerous hooks that can be overridden using modes. Most noteworthy:
  32. mode="topicpull:inherit-attribute"
  33. Can be used to selectively modify how attributes are inherited on a specific element
  34. mode="topicpull:get-stuff_get-linktext" and mode="topicpull:get-stuff_get-shortdesc"
  35. Can be used to determine how link text or shortdesc are retrieved for some types of references
  36. mode="topicpull:getlinktext" and more specific modes "topicpull:getlinktext_*"
  37. Can be used to modify retrieved link text for specific types of elements
  38. mode="topicpull:figure-linktext" and mode="topicpull:table-linktext"
  39. Can be used to modify link style for table and figure references; can
  40. also be used to add support for languages that use different orders.
  41. Note also the TABLELINK and FIGURELINK parameters.
  42. -->
  43. <!-- 20090903 RDA: added <?ditaot gentext?> and <?ditaot linktext?> PIs for RFE 1367897.
  44. Allows downstream processes to identify original text vs. generated link text. -->
  45. <xsl:stylesheet version="2.0"
  46. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  47. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  48. xmlns:topicpull="http://dita-ot.sourceforge.net/ns/200704/topicpull"
  49. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  50. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  51. exclude-result-prefixes="dita-ot topicpull ditamsg xs">
  52. <xsl:import href="../common/dita-utilities.xsl"/>
  53. <xsl:import href="../common/output-message.xsl"/>
  54. <xsl:import href="../common/dita-textonly.xsl"/>
  55. <!-- Define the error message prefix identifier -->
  56. <!-- Deprecated since 2.3 -->
  57. <xsl:variable name="msgprefix">DOTX</xsl:variable>
  58. <xsl:param name="DBG" select="'no'"/>
  59. <!-- Set the format for generated text for links to tables and figures. -->
  60. <!-- Recognized values are 'NUMBER' (Table 5) and 'TITLE' (Table Caption) -->
  61. <xsl:param name="TABLELINK">NUMBER</xsl:param>
  62. <xsl:param name="FIGURELINK">NUMBER</xsl:param>
  63. <!-- Check whether the onlytopicinmap is turned on -->
  64. <xsl:param name="ONLYTOPICINMAP" select="'false'"/>
  65. <!-- Establish keys for the counting of figures, tables, and anything else -->
  66. <!-- To remove something from the figure count, create the same key in an override.
  67. Match all items to be excluded. Set the use attribute to 'exclude'. -->
  68. <xsl:key name="count.topic.fig"
  69. match="*[contains(@class, ' topic/fig ')][*[contains(@class, ' topic/title ')]]"
  70. use="'include'"/>
  71. <xsl:key name="count.topic.table"
  72. match="*[contains(@class, ' topic/table ')][*[contains(@class, ' topic/title ')]]"
  73. use="'include'"/>
  74. <xsl:key name="id" match="*[@id]" use="@id"/>
  75. <xsl:key name="topic" match="*[@id][contains(@class, ' topic/topic ')]" use="@id"/>
  76. <!-- Process a link in the related-links section. Retrieve link text, type, and
  77. description if possible (and not already specified locally). -->
  78. <xsl:template match="*[contains(@class, ' topic/link ')]">
  79. <xsl:if test="@href=''">
  80. <xsl:apply-templates select="." mode="ditamsg:empty-href"/>
  81. </xsl:if>
  82. <xsl:copy>
  83. <!--copy existing explicit attributes-->
  84. <xsl:apply-templates select="@*"/>
  85. <!--copy inheritable attributes that aren't already explicitly defined-->
  86. <!--@type|@format|@scope|@importance|@role-->
  87. <!--need to create type, format, scope variables regardless of whether they exist, for passing as a parameter to getstuff template-->
  88. <xsl:variable name="type" as="xs:string">
  89. <xsl:call-template name="topicpull:inherit"><xsl:with-param name="attrib">type</xsl:with-param></xsl:call-template>
  90. </xsl:variable>
  91. <xsl:variable name="format" as="xs:string">
  92. <xsl:call-template name="topicpull:inherit"><xsl:with-param name="attrib">format</xsl:with-param></xsl:call-template>
  93. </xsl:variable>
  94. <xsl:variable name="scope" as="xs:string">
  95. <xsl:call-template name="topicpull:inherit"><xsl:with-param name="attrib">scope</xsl:with-param></xsl:call-template>
  96. </xsl:variable>
  97. <xsl:if test="not(@type) and $type!='#none#'">
  98. <xsl:attribute name="type"><xsl:value-of select="$type"/></xsl:attribute>
  99. </xsl:if>
  100. <xsl:if test="not(@format) and $format!='#none#'">
  101. <xsl:attribute name="format"><xsl:value-of select="$format"/></xsl:attribute>
  102. </xsl:if>
  103. <xsl:if test="not(@scope) and $scope!='#none#'">
  104. <xsl:attribute name="scope"><xsl:value-of select="$scope"/></xsl:attribute>
  105. </xsl:if>
  106. <xsl:if test="not(@importance)">
  107. <xsl:apply-templates select="." mode="topicpull:inherit-and-set-attribute"><xsl:with-param name="attrib">importance</xsl:with-param></xsl:apply-templates>
  108. </xsl:if>
  109. <xsl:if test="not(@role)">
  110. <xsl:apply-templates select="." mode="topicpull:inherit-and-set-attribute"><xsl:with-param name="attrib">role</xsl:with-param></xsl:apply-templates>
  111. </xsl:if>
  112. <xsl:choose>
  113. <xsl:when test="@type and *[contains(@class, ' topic/linktext ')] and *[contains(@class, ' topic/desc ')]">
  114. <xsl:apply-templates select="." mode="topicpull:add-usertext-PI"/>
  115. <xsl:apply-templates/>
  116. </xsl:when>
  117. <xsl:otherwise>
  118. <!--grab type, text and metadata, as long there's an href to grab from, otherwise error-->
  119. <xsl:choose>
  120. <xsl:when test="@href=''"/>
  121. <xsl:when test="@href">
  122. <xsl:apply-templates select="." mode="topicpull:get-stuff">
  123. <xsl:with-param name="localtype" select="$type"/>
  124. <xsl:with-param name="scope" select="$scope"/>
  125. <xsl:with-param name="format" select="$format"/>
  126. </xsl:apply-templates>
  127. </xsl:when>
  128. <xsl:otherwise>
  129. <xsl:apply-templates select="." mode="ditamsg:missing-href"/>
  130. </xsl:otherwise>
  131. </xsl:choose>
  132. </xsl:otherwise>
  133. </xsl:choose>
  134. </xsl:copy>
  135. </xsl:template>
  136. <!-- 2007.03.13: Update inheritance to check specific elements and attributes.
  137. Similar to the inheritance template in mappull, except that it stops at related links. -->
  138. <xsl:template name="topicpull:inherit">
  139. <xsl:param name="attrib"/>
  140. <xsl:apply-templates select="." mode="topicpull:inherit-from-self-then-ancestor">
  141. <xsl:with-param name="attrib" select="$attrib"/>
  142. </xsl:apply-templates>
  143. </xsl:template>
  144. <!-- Match the attribute which we are trying to inherit -->
  145. <xsl:template match="@*" mode="topicpull:inherit-attribute">
  146. <xsl:value-of select="."/>
  147. </xsl:template>
  148. <!-- If an attribute is specified locally, set it. Otherwise, try to inherit from ancestors. -->
  149. <xsl:template match="*" mode="topicpull:inherit-from-self-then-ancestor">
  150. <xsl:param name="attrib"/>
  151. <xsl:variable name="attrib-here">
  152. <xsl:if test="@*[local-name()=$attrib]"><xsl:value-of select="@*[local-name()=$attrib]"/></xsl:if>
  153. </xsl:variable>
  154. <xsl:choose>
  155. <!-- Any time the attribute is specified on this element, use it -->
  156. <xsl:when test="$attrib-here!=''"><xsl:value-of select="$attrib-here"/></xsl:when>
  157. <!-- Otherwise, use normal inheritance fallback -->
  158. <xsl:otherwise>
  159. <xsl:apply-templates select="." mode="topicpull:inherit-attribute">
  160. <xsl:with-param name="attrib" select="$attrib"/>
  161. </xsl:apply-templates>
  162. </xsl:otherwise>
  163. </xsl:choose>
  164. </xsl:template>
  165. <!-- Match an element when trying to inherit an attribute. Put the value of the attribute in $attrib-here.
  166. * If the attribute is present and should be used ($attrib=here!=''), then use it
  167. * If we are at the related-links element, attribute can't be inherited, so return #none#
  168. * Anything else, move on to parent
  169. -->
  170. <xsl:template match="*" mode="topicpull:inherit-attribute">
  171. <xsl:param name="attrib"/>
  172. <xsl:variable name="attrib-here">
  173. <xsl:apply-templates select="@*[local-name()=$attrib]" mode="topicpull:inherit-attribute"/>
  174. </xsl:variable>
  175. <xsl:choose>
  176. <!-- Any time the attribute is specified on this element, use it -->
  177. <xsl:when test="$attrib-here!=''"><xsl:value-of select="$attrib-here"/></xsl:when>
  178. <!-- No ancestors left to check, so the value is not available. -->
  179. <xsl:when test="contains(@class,' topic/related-links ')">#none#</xsl:when>
  180. <xsl:otherwise>
  181. <xsl:apply-templates select="parent::*" mode="topicpull:inherit-attribute">
  182. <xsl:with-param name="attrib" select="$attrib"/>
  183. </xsl:apply-templates>
  184. </xsl:otherwise>
  185. </xsl:choose>
  186. </xsl:template>
  187. <!-- Similar to the template above, but saves duplicated processing by setting the
  188. attribute when the inherited value != #none# -->
  189. <xsl:template match="*" mode="topicpull:inherit-and-set-attribute">
  190. <xsl:param name="attrib"/>
  191. <xsl:variable name="inherited-value">
  192. <xsl:apply-templates select="." mode="topicpull:inherit-from-self-then-ancestor">
  193. <xsl:with-param name="attrib" select="$attrib"/>
  194. </xsl:apply-templates>
  195. </xsl:variable>
  196. <xsl:if test="$inherited-value!='#none#'">
  197. <xsl:attribute name="{$attrib}"><xsl:value-of select="$inherited-value"/></xsl:attribute>
  198. </xsl:if>
  199. </xsl:template>
  200. <!-- Process an in-line cross reference. Retrieve link text, type, and
  201. description if possible (and not already specified locally). -->
  202. <xsl:template match="*[dita-ot:is-link(.)]">
  203. <!--<xsl:call-template name="verify-href-attribute"/>-->
  204. <xsl:choose>
  205. <xsl:when test="normalize-space(@href)='' or not(@href)">
  206. <xsl:if test="not(@keyref)">
  207. <!-- If keyref is specified, keyref code can generate message about unresolved key -->
  208. <xsl:apply-templates select="." mode="ditamsg:empty-href"/>
  209. </xsl:if>
  210. <xsl:copy>
  211. <xsl:apply-templates select="@*"/>
  212. <xsl:apply-templates select="." mode="topicpull:add-usertext-PI"/>
  213. <xsl:apply-templates select="*|comment()|processing-instruction()|text()"/>
  214. </xsl:copy>
  215. </xsl:when>
  216. <!-- replace "*|text()" with "normalize-space()" to handle xref without
  217. valid link content, in this situation, the xref linktext should be
  218. grabbed from href target. -->
  219. <!-- replace normalize-space() with test for actual valid content. If there is link text
  220. and a <desc> for hover help, do not try to retrieve anything. -->
  221. <xsl:when test="(text()|*[not(contains(@class,' topic/desc '))]) and *[contains(@class,' topic/desc ')]">
  222. <xsl:copy>
  223. <xsl:apply-templates select="@*"/>
  224. <xsl:apply-templates select="." mode="topicpull:add-usertext-PI"/>
  225. <xsl:apply-templates select="*|comment()|processing-instruction()|text()"/>
  226. </xsl:copy>
  227. </xsl:when>
  228. <xsl:when test="@href and not(@href='')">
  229. <xsl:copy>
  230. <xsl:apply-templates select="@*"/>
  231. <!--create variables for attributes that will be passed by parameter to the getstuff template (which is shared with link, which needs the attributes in variables to save doing inheritance checks for each one)-->
  232. <xsl:variable name="type" as="xs:string">
  233. <xsl:choose>
  234. <xsl:when test="@type">
  235. <xsl:value-of select="@type"/>
  236. </xsl:when>
  237. <xsl:otherwise>#none#</xsl:otherwise>
  238. </xsl:choose>
  239. </xsl:variable>
  240. <xsl:variable name="format" as="xs:string">
  241. <xsl:choose>
  242. <xsl:when test="@format">
  243. <xsl:value-of select="@format"/>
  244. </xsl:when>
  245. <xsl:otherwise>#none#</xsl:otherwise>
  246. </xsl:choose>
  247. </xsl:variable>
  248. <xsl:variable name="scope" as="xs:string">
  249. <xsl:choose>
  250. <xsl:when test="@scope">
  251. <xsl:value-of select="@scope"/>
  252. </xsl:when>
  253. <xsl:otherwise>#none#</xsl:otherwise>
  254. </xsl:choose>
  255. </xsl:variable>
  256. <!--grab type, text and metadata, as long there's an href to grab from, otherwise error-->
  257. <xsl:apply-templates select="." mode="topicpull:get-stuff">
  258. <xsl:with-param name="localtype" select="$type"/>
  259. <xsl:with-param name="scope" select="$scope"/>
  260. <xsl:with-param name="format" select="$format"/>
  261. </xsl:apply-templates>
  262. </xsl:copy>
  263. </xsl:when>
  264. <!-- Ignore <xref></xref>, <xref href=""></xref> -->
  265. <xsl:otherwise>
  266. <xsl:apply-templates select="." mode="ditamsg:missing-href"/>
  267. <xsl:copy>
  268. <xsl:apply-templates select="@*"/>
  269. <xsl:apply-templates select="." mode="topicpull:add-usertext-PI"/>
  270. <xsl:apply-templates select="*|comment()|processing-instruction()|text()"/>
  271. </xsl:copy>
  272. </xsl:otherwise>
  273. </xsl:choose>
  274. </xsl:template>
  275. <!-- verify the href attribute, to check whether href target can be retrieved. -->
  276. <xsl:template name="verify-href-attribute">
  277. <xsl:param name="base-uri" as="xs:anyURI" tunnel="yes" select="base-uri(.)"/>
  278. <xsl:variable name="format" as="xs:string">
  279. <xsl:choose>
  280. <xsl:when test="@format">
  281. <xsl:value-of select="@format"/>
  282. </xsl:when>
  283. <xsl:otherwise>#none#</xsl:otherwise>
  284. </xsl:choose>
  285. </xsl:variable>
  286. <xsl:variable name="scope" as="xs:string">
  287. <xsl:choose>
  288. <xsl:when test="@scope">
  289. <xsl:value-of select="@scope"/>
  290. </xsl:when>
  291. <xsl:otherwise>#none#</xsl:otherwise>
  292. </xsl:choose>
  293. </xsl:variable>
  294. <!--the file name of the target, if any-->
  295. <xsl:variable name="file" select="resolve-uri(dita-ot:strip-fragment(@href), $base-uri)" as="xs:anyURI"/>
  296. <!--the position of the target topic relative to the current one: in the same file, referenced by id in another file, or referenced as the first topic in another file-->
  297. <xsl:variable name="topicpos" as="xs:string">
  298. <xsl:apply-templates select="." mode="topicpull:get-stuff_topicpos"/>
  299. </xsl:variable>
  300. <!--the id of the target topic-->
  301. <xsl:variable name="topicid" as="xs:string">
  302. <xsl:apply-templates select="." mode="topicpull:get-stuff_topicid"/>
  303. </xsl:variable>
  304. <!--the id of the target element, if any-->
  305. <xsl:variable name="elemid" as="xs:string">
  306. <xsl:apply-templates select="." mode="topicpull:get-stuff_elemid"/>
  307. </xsl:variable>
  308. <xsl:variable name="doc" select="document($file,/)"/>
  309. <xsl:choose>
  310. <xsl:when test="not($scope='external') and not($scope='peer') and $topicpos='samefile'">
  311. <xsl:choose>
  312. <xsl:when test="$topicid='' or not(key('topic', $topicid)) or $topicid='#none#' ">
  313. <xsl:call-template name="output-message">
  314. <xsl:with-param name="id" select="'DOTX057W'"/>
  315. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/>
  316. </xsl:with-param>
  317. </xsl:call-template>
  318. </xsl:when>
  319. <xsl:when test="not($elemid='') and not($elemid='#none#') and not(key('topic', $topicid)//*[@id=$elemid])">
  320. <xsl:call-template name="output-message">
  321. <xsl:with-param name="id" select="'DOTX057W'"/>
  322. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/>
  323. </xsl:with-param>
  324. </xsl:call-template>
  325. </xsl:when>
  326. </xsl:choose>
  327. </xsl:when>
  328. <xsl:when test="($format='dita' or $format='#none#') and not($scope='external') and not($scope='peer') and $topicpos='otherfile' and not(contains(@href,'://'))">
  329. <xsl:choose>
  330. <xsl:when test="not($doc) or not($doc/*/*)">
  331. <xsl:call-template name="output-message">
  332. <xsl:with-param name="id" select="'DOTX057W'"/>
  333. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/>
  334. </xsl:with-param>
  335. </xsl:call-template>
  336. </xsl:when>
  337. <xsl:when test="not($doc//*[contains(@class,' topic/topic ')][@id=$topicid])">
  338. <xsl:call-template name="output-message">
  339. <xsl:with-param name="id" select="'DOTX057W'"/>
  340. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/>
  341. </xsl:with-param>
  342. </xsl:call-template>
  343. </xsl:when>
  344. <xsl:when test="not($elemid='') and not($elemid='#none#') and not(key('topic', $topicid)//*[@id=$elemid])">
  345. <xsl:call-template name="output-message">
  346. <xsl:with-param name="id" select="'DOTX057W'"/>
  347. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/>
  348. </xsl:with-param>
  349. </xsl:call-template>
  350. </xsl:when>
  351. </xsl:choose>
  352. </xsl:when>
  353. <xsl:otherwise>
  354. <xsl:if test="($format='dita' or $format='#none#') and not($scope='external') and not($scope='peer') and not($doc) and not(contains(@href,'://'))">
  355. <xsl:call-template name="output-message">
  356. <xsl:with-param name="id" select="'DOTX057W'"/>
  357. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/>
  358. </xsl:with-param>
  359. </xsl:call-template>
  360. </xsl:if>
  361. </xsl:otherwise>
  362. </xsl:choose>
  363. </xsl:template>
  364. <!-- Verify that a locally specified type attribute matches the determined target type.
  365. If it does not, generate a message. -->
  366. <xsl:template match="*" mode="topicpull:verify-type-attribute">
  367. <xsl:param name="type"/> <!-- Type value specified on the link -->
  368. <xsl:param name="actual-class"/> <!-- Class value of the target element -->
  369. <xsl:param name="actual-name"/> <!-- Name of the target element -->
  370. <xsl:param name="targetting"/> <!-- Targetting a "topic" or "element" -->
  371. <xsl:choose>
  372. <!-- The type is correct; concept typed as concept, newtype defined as newtype -->
  373. <xsl:when test="$type=$actual-name"/>
  374. <!-- If the actual class contains the specified type; reference can be called topic,
  375. specializedReference can be called reference -->
  376. <xsl:when test="($targetting='topic' and contains($actual-class,concat(' ',$type,'/',$type,' '))) or
  377. ($targetting='element' and contains($actual-class,concat('/',$type,' ')))">
  378. <xsl:apply-templates select="." mode="ditamsg:type-attribute-not-specific">
  379. <xsl:with-param name="targetting" select="$targetting"/>
  380. <xsl:with-param name="type" select="$type"/>
  381. <xsl:with-param name="actual-name" select="$actual-name"/>
  382. </xsl:apply-templates>
  383. </xsl:when>
  384. <!-- Otherwise: incorrect type is specified -->
  385. <xsl:otherwise>
  386. <xsl:apply-templates select="." mode="ditamsg:type-attribute-incorrect">
  387. <xsl:with-param name="targetting" select="$targetting"/>
  388. <xsl:with-param name="type" select="$type"/>
  389. <xsl:with-param name="actual-name" select="$actual-name"/>
  390. </xsl:apply-templates>
  391. </xsl:otherwise>
  392. </xsl:choose>
  393. </xsl:template>
  394. <!-- Get link text, type, and short description for a link or cross reference.
  395. If specified locally, use the local value, otherwise retrieve from target. -->
  396. <xsl:template match="*" mode="topicpull:get-stuff">
  397. <xsl:param name="localtype" as="xs:string"/>
  398. <xsl:param name="scope" as="xs:string"/>
  399. <xsl:param name="format" as="xs:string"/>
  400. <xsl:param name="base-uri" as="xs:anyURI" tunnel="yes" select="base-uri(.)"/>
  401. <!--the file name of the target, if any-->
  402. <xsl:variable name="file" select="resolve-uri(dita-ot:strip-fragment(@href), $base-uri)" as="xs:anyURI"/>
  403. <!--the position of the target topic relative to the current one: in the same file, referenced by id in another file, or referenced as the first topic in another file-->
  404. <xsl:variable name="topicpos" as="xs:string"><xsl:apply-templates select="." mode="topicpull:get-stuff_topicpos"/></xsl:variable>
  405. <xsl:apply-templates select="." mode="topicpull:get-stuff_verify-target-present">
  406. <xsl:with-param name="topicpos" select="$topicpos"/>
  407. <xsl:with-param name="scope" select="$scope"/>
  408. <xsl:with-param name="format" select="$format"/>
  409. <xsl:with-param name="file" select="$file"/>
  410. </xsl:apply-templates>
  411. <!--the id of the target topic-->
  412. <xsl:variable name="topicid" as="xs:string">
  413. <xsl:apply-templates select="." mode="topicpull:get-stuff_topicid"/>
  414. </xsl:variable>
  415. <!--the id of the target element, if any-->
  416. <xsl:variable name="elemid" as="xs:string">
  417. <xsl:apply-templates select="." mode="topicpull:get-stuff_elemid"/>
  418. </xsl:variable>
  419. <!--type - grab type from target, if not defined locally -->
  420. <xsl:variable name="type" as="xs:string?">
  421. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-type">
  422. <xsl:with-param name="localtype" select="$localtype"/>
  423. <xsl:with-param name="scope" select="$scope"/>
  424. <xsl:with-param name="format" select="$format"/>
  425. <xsl:with-param name="topicpos" select="$topicpos"/>
  426. <xsl:with-param name="file" select="$file"/>
  427. <xsl:with-param name="topicid" select="$topicid"/>
  428. <xsl:with-param name="elemid" select="$elemid"/>
  429. </xsl:apply-templates>
  430. </xsl:variable>
  431. <!--now, create the type attribute, if the type attribute didn't exist locally but was retrieved successfully-->
  432. <xsl:if test="$localtype='#none#' and not($type='#none#')">
  433. <xsl:attribute name="type"><xsl:value-of select="$type"/></xsl:attribute>
  434. </xsl:if>
  435. <!-- Verify that the type was correct, if specified locally, and DITA target is available -->
  436. <xsl:apply-templates select="." mode="topicpull:get-stuff_verify-type">
  437. <xsl:with-param name="localtype" select="$localtype"/>
  438. <xsl:with-param name="scope" select="$scope"/>
  439. <xsl:with-param name="format" select="$format"/>
  440. <xsl:with-param name="topicpos" select="$topicpos"/>
  441. <xsl:with-param name="file" select="$file"/>
  442. <xsl:with-param name="topicid" select="$topicid"/>
  443. <xsl:with-param name="elemid" select="$elemid"/>
  444. </xsl:apply-templates>
  445. <!--create class value string implied by the link's type, used for comparison with class strings in the target topic for validation-->
  446. <xsl:variable name="classval">
  447. <xsl:apply-templates select="." mode="topicpull:get-stuff_classval"><xsl:with-param name="type" select="$type"/></xsl:apply-templates>
  448. </xsl:variable>
  449. <!--linktext-->
  450. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-linktext">
  451. <xsl:with-param name="type" select="$type"/>
  452. <xsl:with-param name="scope" select="$scope"/>
  453. <xsl:with-param name="format" select="$format"/>
  454. <xsl:with-param name="topicpos" select="$topicpos"/>
  455. <xsl:with-param name="file" select="$file"/>
  456. <xsl:with-param name="topicid" select="$topicid"/>
  457. <xsl:with-param name="elemid" select="$elemid"/>
  458. <xsl:with-param name="classval" select="$classval"/>
  459. </xsl:apply-templates>
  460. <!-- shortdesc -->
  461. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-shortdesc">
  462. <xsl:with-param name="type" select="$type"/>
  463. <xsl:with-param name="scope" select="$scope"/>
  464. <xsl:with-param name="format" select="$format"/>
  465. <xsl:with-param name="topicpos" select="$topicpos"/>
  466. <xsl:with-param name="file" select="$file"/>
  467. <xsl:with-param name="topicid" select="$topicid"/>
  468. <xsl:with-param name="elemid" select="$elemid"/>
  469. <xsl:with-param name="classval" select="$classval"/>
  470. </xsl:apply-templates>
  471. </xsl:template>
  472. <!-- ******************************************************************************
  473. Individual portions of get-stuff processing, broken apart for easy overriding.
  474. If a template overrides all of get-stuff, most of these templates can still be
  475. used so as to avoid duplicating processing code in the override.
  476. ************************************************************************** -->
  477. <!-- Determine where the target of a reference exists -->
  478. <xsl:template match="*" mode="topicpull:get-stuff_topicpos" as="xs:string">
  479. <xsl:choose>
  480. <xsl:when test="starts-with(@href,'#')">samefile</xsl:when>
  481. <xsl:when test="contains(@href,'#')">otherfile</xsl:when>
  482. <xsl:otherwise>firstinfile</xsl:otherwise>
  483. </xsl:choose>
  484. </xsl:template>
  485. <!-- If target is in another file, warn when that file cannot be found -->
  486. <xsl:template match="*" mode="topicpull:get-stuff_verify-target-present">
  487. <xsl:param name="topicpos"/>
  488. <xsl:param name="scope"/>
  489. <xsl:param name="format"/>
  490. <xsl:param name="file"/>
  491. <xsl:if test="$topicpos!='samefile' and
  492. ($scope!='external' and $scope!='peer') and
  493. ($format='dita' or $format='#none#')">
  494. <xsl:variable name="doc" select="document($file,/)"/>
  495. <xsl:if test="not($doc) or not($doc/*/*)">
  496. <xsl:apply-templates select="." mode="ditamsg:missing-href-target">
  497. <xsl:with-param name="file" select="$file"/>
  498. </xsl:apply-templates>
  499. </xsl:if>
  500. </xsl:if>
  501. </xsl:template>
  502. <!-- Pick out the topic ID from an href value -->
  503. <xsl:template match="*" mode="topicpull:get-stuff_topicid" as="xs:string">
  504. <xsl:variable name="topic-id" select="dita-ot:get-topic-id(@href)" as="xs:string?"/>
  505. <xsl:choose>
  506. <xsl:when test="exists($topic-id)">
  507. <xsl:value-of select="$topic-id"/>
  508. </xsl:when>
  509. <xsl:otherwise>#none#</xsl:otherwise>
  510. </xsl:choose>
  511. </xsl:template>
  512. <!-- Pick out the element ID from an href value -->
  513. <xsl:template match="*" mode="topicpull:get-stuff_elemid" as="xs:string">
  514. <xsl:variable name="element-id" select="dita-ot:get-element-id(@href)" as="xs:string?"/>
  515. <xsl:choose>
  516. <xsl:when test="exists($element-id)">
  517. <xsl:value-of select="$element-id"/>
  518. </xsl:when>
  519. <xsl:otherwise>#none#</xsl:otherwise>
  520. </xsl:choose>
  521. </xsl:template>
  522. <!-- Get the type from target, if not defined locally -->
  523. <xsl:template match="*" mode="topicpull:get-stuff_get-type" as="xs:string?">
  524. <xsl:param name="localtype"/>
  525. <xsl:param name="scope"/>
  526. <xsl:param name="format"/>
  527. <xsl:param name="topicpos"/>
  528. <xsl:param name="file"/>
  529. <xsl:param name="topicid"/>
  530. <xsl:param name="elemid"/>
  531. <xsl:choose>
  532. <!--just use localtype if it's not "none"-->
  533. <xsl:when test="not($localtype='#none#')"><xsl:value-of select="$localtype"/></xsl:when>
  534. <!--check whether it's worth trying to retrieve-->
  535. <xsl:when test="$scope='external' or $scope='peer' or not($format='#none#' or $format='dita')"><xsl:text>#none#</xsl:text><!--type is unavailable--></xsl:when>
  536. <!-- If this is an empty href, ignore it; we already put out a message -->
  537. <xsl:when test="@href=''"/>
  538. <!--grab from target topic-->
  539. <xsl:when test="$elemid='#none#'">
  540. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-type-without-elemid">
  541. <xsl:with-param name="topicpos" select="$topicpos"/>
  542. <xsl:with-param name="file" select="$file"/>
  543. <xsl:with-param name="topicid" select="$topicid"/>
  544. </xsl:apply-templates>
  545. </xsl:when>
  546. <!--grab type from target element-->
  547. <xsl:when test="$localtype='#none#'">
  548. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-type-with-elemid">
  549. <xsl:with-param name="topicpos" select="$topicpos"/>
  550. <xsl:with-param name="file" select="$file"/>
  551. <xsl:with-param name="topicid" select="$topicid"/>
  552. <xsl:with-param name="elemid" select="$elemid"/>
  553. </xsl:apply-templates>
  554. </xsl:when>
  555. <xsl:otherwise>
  556. <!--tested both conditions for localtype (exists or not), so no otherwise-->
  557. </xsl:otherwise>
  558. </xsl:choose>
  559. </xsl:template>
  560. <!-- Get the type when pointing to a topic level element -->
  561. <xsl:template match="*" mode="topicpull:get-stuff_get-type-without-elemid" as="xs:string">
  562. <xsl:param name="topicpos"/>
  563. <xsl:param name="file"/>
  564. <xsl:param name="topicid"/>
  565. <xsl:variable name="doc" select="document($file,/)"/>
  566. <xsl:choose>
  567. <xsl:when test="$topicpos='samefile'">
  568. <xsl:choose>
  569. <xsl:when test="key('topic', $topicid)">
  570. <xsl:value-of select="local-name(key('topic', $topicid))"/>
  571. </xsl:when>
  572. <!--type could not be retrieved-->
  573. <xsl:otherwise>#none#</xsl:otherwise>
  574. </xsl:choose>
  575. </xsl:when>
  576. <xsl:when test="$topicpos='otherfile'">
  577. <xsl:choose>
  578. <xsl:when test="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]">
  579. <xsl:value-of select="local-name($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])"/>
  580. </xsl:when>
  581. <!--type could not be retrieved-->
  582. <xsl:otherwise>#none#</xsl:otherwise>
  583. </xsl:choose>
  584. </xsl:when>
  585. <xsl:when test="$topicpos='firstinfile'">
  586. <xsl:choose>
  587. <xsl:when test="$doc//*[contains(@class, ' topic/topic ')][1]">
  588. <xsl:value-of select="local-name(($doc//*[contains(@class, ' topic/topic ')])[1])"/>
  589. </xsl:when>
  590. <!--type could not be retrieved-->
  591. <xsl:otherwise>#none#</xsl:otherwise>
  592. </xsl:choose>
  593. </xsl:when>
  594. <xsl:otherwise>
  595. <!--never happens - all three values for topicpos are tested-->
  596. </xsl:otherwise>
  597. </xsl:choose>
  598. </xsl:template>
  599. <!-- Get the type from an element within topic -->
  600. <xsl:template match="*" mode="topicpull:get-stuff_get-type-with-elemid" as="xs:string">
  601. <xsl:param name="topicpos"/>
  602. <xsl:param name="file"/>
  603. <xsl:param name="topicid"/>
  604. <xsl:param name="elemid"/>
  605. <xsl:variable name="doc" select="document($file,/)"/>
  606. <xsl:choose>
  607. <xsl:when test="$topicpos='samefile'">
  608. <xsl:choose>
  609. <xsl:when test="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid]">
  610. <xsl:value-of select="local-name(key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid])"/>
  611. </xsl:when>
  612. <!--type could not be retrieved-->
  613. <xsl:otherwise>#none#</xsl:otherwise>
  614. </xsl:choose>
  615. </xsl:when>
  616. <xsl:when test="$topicpos='otherfile'">
  617. <xsl:choose>
  618. <xsl:when test="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid]">
  619. <xsl:value-of select="local-name($doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid])"/>
  620. </xsl:when>
  621. <!--type could not be retrieved-->
  622. <xsl:otherwise>#none#</xsl:otherwise>
  623. </xsl:choose>
  624. </xsl:when>
  625. <xsl:otherwise>
  626. <!--never happens - must be either same file or other file, firstinfile not possible if there's an element id present-->
  627. </xsl:otherwise>
  628. </xsl:choose>
  629. </xsl:template>
  630. <!-- Find the class attribute of the reference topic. Determine if the specified type
  631. exists in that class attribute. -->
  632. <xsl:template match="*" mode="topicpull:get-stuff_verify-type">
  633. <xsl:param name="localtype"/>
  634. <xsl:param name="scope"/>
  635. <xsl:param name="format"/>
  636. <xsl:param name="topicpos"/>
  637. <xsl:param name="file"/>
  638. <xsl:param name="topicid"/>
  639. <xsl:param name="elemid"/>
  640. <xsl:if test="$localtype!='#none#' and
  641. not(@scope='external' or @scope='peer') and
  642. ((not(@format) or @format='dita') or starts-with(@href,'#'))">
  643. <xsl:variable name="doc" select="document($file,/)"/>
  644. <xsl:choose>
  645. <!-- If this is an xref, there can't be any elements or text inside -->
  646. <xsl:when test="dita-ot:is-link(.) and not(*[not(contains(@class,' topic/desc '))]|text())">
  647. <xsl:choose>
  648. <!-- targetting an element in the same file (not a topic) -->
  649. <xsl:when test="$topicpos='samefile' and $elemid!='#none#' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid]">
  650. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  651. <xsl:with-param name="type" select="$localtype"/>
  652. <xsl:with-param name="actual-class" select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][1]/@class"/>
  653. <xsl:with-param name="actual-name" select="local-name(key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][1])"/>
  654. <xsl:with-param name="targetting">element</xsl:with-param>
  655. </xsl:apply-templates>
  656. </xsl:when>
  657. <!-- targetting a topic in the same file -->
  658. <xsl:when test="$topicpos='samefile' and $elemid='#none#' and key('topic', $topicid)">
  659. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  660. <xsl:with-param name="type" select="$localtype"/>
  661. <xsl:with-param name="actual-class" select="key('topic', $topicid)[1]/@class"/>
  662. <xsl:with-param name="actual-name" select="local-name(key('topic', $topicid)[1])"/>
  663. <xsl:with-param name="targetting">topic</xsl:with-param>
  664. </xsl:apply-templates>
  665. </xsl:when>
  666. <!-- targetting an element in another file (not a topic) -->
  667. <xsl:when test="$topicpos='otherfile' and $elemid!='#none#' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid]">
  668. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  669. <xsl:with-param name="type" select="$localtype"/>
  670. <xsl:with-param name="actual-class" select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid])[1]/@class"/>
  671. <xsl:with-param name="actual-name" select="local-name(($doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid])[1])"/>
  672. <xsl:with-param name="targetting">element</xsl:with-param>
  673. </xsl:apply-templates>
  674. </xsl:when>
  675. <!-- targetting a topic in another file -->
  676. <xsl:when test="$topicpos='otherfile' and $elemid='#none#' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]">
  677. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  678. <xsl:with-param name="type" select="$localtype"/>
  679. <xsl:with-param name="actual-class" select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/@class"/>
  680. <xsl:with-param name="actual-name" select="local-name(($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1])"/>
  681. <xsl:with-param name="targetting">topic</xsl:with-param>
  682. </xsl:apply-templates>
  683. </xsl:when>
  684. <!-- targetting a topic in another file -->
  685. <xsl:when test="$topicpos='firstinfile' and $doc//*[contains(@class, ' topic/topic ')]">
  686. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  687. <xsl:with-param name="type" select="$localtype"/>
  688. <xsl:with-param name="actual-class" select="($doc//*[contains(@class, ' topic/topic ')])[1]/@class"/>
  689. <xsl:with-param name="actual-name" select="local-name(($doc//*[contains(@class, ' topic/topic ')])[1])"/>
  690. <xsl:with-param name="targetting">topic</xsl:with-param>
  691. </xsl:apply-templates>
  692. </xsl:when>
  693. </xsl:choose>
  694. </xsl:when>
  695. <!-- If this is a link, linktext, linkdesc, or @type must be missing.
  696. There should not be any links with element IDs, but put in the check just to be sure. -->
  697. <!-- If linktext, desc, and @type are all specified, we won't be here, so assume something is not specified. -->
  698. <xsl:when test="contains(@class,' topic/link ')">
  699. <xsl:choose>
  700. <!-- If there is a link to an element (error condition, so skip) -->
  701. <xsl:when test="$elemid!='#none#'"/>
  702. <!-- If we know this link came from a map, it has already been checked -->
  703. <xsl:when test="contains(@xtrf,'.ditamap')"/>
  704. <xsl:when test="ancestor::*[contains(@class, ' topic/linkpool ')]/@mapkeyref"/>
  705. <xsl:otherwise>
  706. <xsl:choose>
  707. <!-- targetting a topic in this file -->
  708. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)">
  709. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  710. <xsl:with-param name="type" select="$localtype"/>
  711. <xsl:with-param name="actual-class" select="key('topic', $topicid)[1]/@class"/>
  712. <xsl:with-param name="actual-name" select="local-name(key('topic', $topicid)[1])"/>
  713. <xsl:with-param name="targetting">topic</xsl:with-param>
  714. </xsl:apply-templates>
  715. </xsl:when>
  716. <!-- targetting a topic in another file -->
  717. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]">
  718. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  719. <xsl:with-param name="type" select="$localtype"/>
  720. <xsl:with-param name="actual-class" select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/@class"/>
  721. <xsl:with-param name="actual-name" select="local-name(($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1])"/>
  722. <xsl:with-param name="targetting">topic</xsl:with-param>
  723. </xsl:apply-templates>
  724. </xsl:when>
  725. <!-- targetting the first topic in another file -->
  726. <xsl:when test="$topicpos='firstinfile' and $doc//*[contains(@class, ' topic/topic ')]">
  727. <xsl:apply-templates select="." mode="topicpull:verify-type-attribute">
  728. <xsl:with-param name="type" select="$localtype"/>
  729. <xsl:with-param name="actual-class" select="($doc//*[contains(@class, ' topic/topic ')])[1]/@class"/>
  730. <xsl:with-param name="actual-name" select="local-name(($doc//*[contains(@class, ' topic/topic ')])[1])"/>
  731. <xsl:with-param name="targetting">topic</xsl:with-param>
  732. </xsl:apply-templates>
  733. </xsl:when>
  734. </xsl:choose>
  735. </xsl:otherwise>
  736. </xsl:choose>
  737. </xsl:when>
  738. </xsl:choose>
  739. </xsl:if>
  740. </xsl:template>
  741. <!--template used to construct the class value used to validate link targets against source types. -->
  742. <xsl:template match="*" mode="topicpull:get-stuff_classval">
  743. <xsl:param name="type">#none#</xsl:param>
  744. <xsl:choose>
  745. <!--if type doesn't exist, assume target is a topic of some kind-->
  746. <xsl:when test="$type='#none#'"><xsl:text> topic/topic </xsl:text></xsl:when>
  747. <!--if there is an element id, construct a partial classvalue and just use that-->
  748. <xsl:when test="dita-ot:has-element-id(@href)">
  749. <xsl:text>/</xsl:text><xsl:value-of select="$type"/><xsl:text> </xsl:text>
  750. </xsl:when>
  751. <!-- otherwise there's a type but no element id, so construct a root element classvalue, eg task/task or concept/concept-->
  752. <xsl:otherwise>
  753. <xsl:text> </xsl:text>
  754. <xsl:value-of select="$type"/>/<xsl:value-of select="$type"/>
  755. <xsl:text> </xsl:text>
  756. </xsl:otherwise>
  757. </xsl:choose>
  758. </xsl:template>
  759. <!-- Get the short description for a link or xref -->
  760. <xsl:template match="*" mode="topicpull:get-stuff_get-shortdesc">
  761. <xsl:param name="type"/>
  762. <xsl:param name="scope"/>
  763. <xsl:param name="format"/>
  764. <xsl:param name="topicpos"/>
  765. <xsl:param name="file"/>
  766. <xsl:param name="topicid"/>
  767. <xsl:param name="elemid"/>
  768. <xsl:param name="classval"/>
  769. <xsl:choose>
  770. <!--if there's already a desc, copy it-->
  771. <xsl:when test="*[contains(@class, ' topic/desc ')]">
  772. <xsl:apply-templates select="." mode="topicpull:add-usershortdesc-PI"/>
  773. <xsl:apply-templates select="*[contains(@class, ' topic/desc ')]"/>
  774. </xsl:when>
  775. <!--if the target is inaccessible, don't do anything - shortdesc is optional -->
  776. <xsl:when test="$scope='external' or $scope='peer' or $type='external' or not($format='#none#' or $format='dita')"/>
  777. <!--otherwise try pulling shortdesc from target-->
  778. <xsl:otherwise>
  779. <xsl:variable name="shortdesc">
  780. <xsl:apply-templates select="." mode="topicpull:getshortdesc">
  781. <xsl:with-param name="file" select="$file"/>
  782. <xsl:with-param name="topicpos" select="$topicpos"/>
  783. <xsl:with-param name="classval" select="$classval"/>
  784. <xsl:with-param name="topicid" select="$topicid"/>
  785. <xsl:with-param name="elemid" select="$elemid"/>
  786. </xsl:apply-templates>
  787. </xsl:variable>
  788. <xsl:if test="not($shortdesc='#none#')">
  789. <xsl:apply-templates select="." mode="topicpull:add-genshortdesc-PI"/>
  790. <desc class="- topic/desc ">
  791. <xsl:apply-templates select="$shortdesc">
  792. <xsl:with-param name="base-uri" select="$file" as="xs:anyURI" tunnel="yes"/>
  793. </xsl:apply-templates>
  794. </desc>
  795. </xsl:if>
  796. </xsl:otherwise>
  797. </xsl:choose>
  798. </xsl:template>
  799. <!-- Ignore desc in elements that do now support it. -->
  800. <xsl:template match="*[contains(@class,' topic/cite ') or
  801. contains(@class,' topic/dt ') or
  802. contains(@class,' topic/keyword ') or
  803. contains(@class,' topic/term ') or
  804. contains(@class,' topic/ph ') or
  805. contains(@class,' topic/indexterm ') or
  806. contains(@class,' topic/index-base ') or
  807. contains(@class,' topic/indextermref ')]"
  808. mode="topicpull:get-stuff_get-shortdesc" priority="10"/>
  809. <!-- Get the link text for a link or cross reference. If specified locally, use that. Otherwise,
  810. work with the target to get the text. -->
  811. <xsl:template match="*" mode="topicpull:get-stuff_get-linktext">
  812. <xsl:param name="type"/>
  813. <xsl:param name="scope"/>
  814. <xsl:param name="format"/>
  815. <xsl:param name="topicpos"/>
  816. <xsl:param name="file"/>
  817. <xsl:param name="topicid"/>
  818. <xsl:param name="elemid"/>
  819. <xsl:param name="classval"/>
  820. <xsl:choose>
  821. <xsl:when test="contains(@class,' topic/link ') and *[not(contains(@class, ' topic/desc '))]">
  822. <xsl:apply-templates select="." mode="topicpull:add-usertext-PI"/>
  823. <xsl:apply-templates select="*[not(contains(@class, ' topic/desc '))]|comment()|processing-instruction()"/>
  824. </xsl:when>
  825. <xsl:when test="dita-ot:is-link(.) and (normalize-space(.) != '' or *[not(contains(@class, ' topic/desc '))])">
  826. <xsl:apply-templates select="." mode="topicpull:add-usertext-PI"/>
  827. <xsl:apply-templates select="text()|*[not(contains(@class, ' topic/desc '))]|comment()|processing-instruction()"/>
  828. </xsl:when>
  829. <xsl:otherwise>
  830. <xsl:variable name="linktext">
  831. <xsl:choose>
  832. <!--when type is external, or format is defaulted to not-DITA
  833. (because scope is external), or format is explicitly something
  834. non-DITA, use the href value with no error message-->
  835. <xsl:when test="$type='external' or
  836. ($scope='external' and $format='#none#') or
  837. not($format='#none#' or $format='dita')">
  838. <xsl:value-of select="@href"/>
  839. </xsl:when>
  840. <!--when scope is external or peer and format is DITA, don't use
  841. the href - defer to the final output process - and leave it
  842. to the final output process to emit an error msg-->
  843. <xsl:when test="$scope='peer' or $scope='external'">#none#</xsl:when>
  844. <xsl:when test="@href=''">#none#</xsl:when>
  845. <!-- otherwise pull text from the target -->
  846. <xsl:otherwise>
  847. <xsl:apply-templates select="." mode="topicpull:getlinktext">
  848. <xsl:with-param name="file" select="$file"/>
  849. <xsl:with-param name="topicpos" select="$topicpos"/>
  850. <xsl:with-param name="classval" select="$classval"/>
  851. <xsl:with-param name="topicid" select="$topicid"/>
  852. <xsl:with-param name="elemid" select="$elemid"/>
  853. </xsl:apply-templates>
  854. </xsl:otherwise>
  855. </xsl:choose>
  856. </xsl:variable>
  857. <xsl:if test="not($linktext='#none#') and dita-ot:is-link(.)">
  858. <!-- need to avoid flattening complex markup here-->
  859. <xsl:apply-templates select="." mode="topicpull:add-gentext-PI"/>
  860. <xsl:value-of select="$linktext"/>
  861. </xsl:if>
  862. <xsl:if test="not($linktext='#none#') and contains(@class, ' topic/link ')">
  863. <xsl:apply-templates select="." mode="topicpull:add-gentext-PI"/>
  864. <linktext class="- topic/linktext ">
  865. <xsl:value-of select="$linktext"/>
  866. </linktext>
  867. </xsl:if>
  868. </xsl:otherwise>
  869. </xsl:choose>
  870. </xsl:template>
  871. <xsl:variable name="link-classes" as="xs:string*"
  872. select="(' topic/cite ',
  873. ' topic/dt ',
  874. ' topic/keyword ',
  875. ' topic/term ',
  876. ' topic/ph ',
  877. ' topic/indexterm ',
  878. ' topic/index-base ',
  879. ' topic/indextermref ')"/>
  880. <xsl:function name="dita-ot:is-link" as="xs:boolean">
  881. <xsl:param name="node"/>
  882. <xsl:sequence select="contains($node/@class,' topic/xref ') or
  883. ($node/@href and not(contains($node/@class,' delay-d/anchorkey ')) and (some $c in $link-classes satisfies contains($node/@class, $c)))"/>
  884. </xsl:function>
  885. <!-- Called when retrieving text for a link or xref. Determine if the reference
  886. points to a topic, or to an element, and process accordingly. -->
  887. <xsl:template match="*" mode="topicpull:getlinktext">
  888. <xsl:param name="file">#none#</xsl:param>
  889. <xsl:param name="topicpos" as="xs:string"/>
  890. <xsl:param name="classval">#none#</xsl:param>
  891. <xsl:param name="topicid">#none#</xsl:param>
  892. <xsl:param name="elemid">#none#</xsl:param>
  893. <xsl:choose>
  894. <xsl:when test="dita-ot:has-element-id(@href)">
  895. <!-- Points to an element within a topic -->
  896. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic">
  897. <xsl:with-param name="file" select="$file"/>
  898. <xsl:with-param name="topicpos" select="$topicpos"/>
  899. <xsl:with-param name="classval" select="$classval"/>
  900. <xsl:with-param name="topicid" select="$topicid"/>
  901. <xsl:with-param name="elemid" select="$elemid"/>
  902. </xsl:apply-templates>
  903. </xsl:when>
  904. <xsl:otherwise>
  905. <!-- Points to a topic, not an element within a topic -->
  906. <xsl:apply-templates select="." mode="topicpull:getlinktext_topic">
  907. <xsl:with-param name="file" select="$file"/>
  908. <xsl:with-param name="topicpos" select="$topicpos"/>
  909. <xsl:with-param name="classval" select="$classval"/>
  910. <xsl:with-param name="topicid" select="$topicid"/>
  911. </xsl:apply-templates>
  912. </xsl:otherwise>
  913. </xsl:choose>
  914. </xsl:template>
  915. <!-- Get the link text for a reference to a topic. Already verified that
  916. topic should be available (scope!=external, etc). -->
  917. <xsl:template match="*" mode="topicpull:getlinktext_topic">
  918. <xsl:param name="file">#none#</xsl:param>
  919. <xsl:param name="topicpos" as="xs:string"/>
  920. <xsl:param name="classval">#none#</xsl:param>
  921. <xsl:param name="topicid">#none#</xsl:param>
  922. <xsl:choose>
  923. <!--targetting a topic in the same file-->
  924. <xsl:when test="$topicpos='samefile'">
  925. <xsl:apply-templates select="." mode="topicpull:getlinktext-samefile">
  926. <xsl:with-param name="classval" select="$classval"/>
  927. <xsl:with-param name="topicid" select="$topicid"/>
  928. </xsl:apply-templates>
  929. </xsl:when>
  930. <!--targetting the first topic in a target file-->
  931. <xsl:when test="$topicpos='firstinfile'">
  932. <xsl:apply-templates select="." mode="topicpull:getlinktext-firstinfile">
  933. <xsl:with-param name="file" select="$file"/>
  934. <xsl:with-param name="classval" select="$classval"/>
  935. </xsl:apply-templates>
  936. </xsl:when>
  937. <!--targetting a particular topic in another file-->
  938. <xsl:when test="$topicpos='otherfile'">
  939. <xsl:apply-templates select="." mode="topicpull:getlinktext-otherfile">
  940. <xsl:with-param name="file" select="$file"/>
  941. <xsl:with-param name="classval" select="$classval"/>
  942. <xsl:with-param name="topicid" select="$topicid"/>
  943. </xsl:apply-templates>
  944. </xsl:when>
  945. <xsl:otherwise>
  946. <!--tested all three values for topicpos, for both topics and elements - no otherwise-->
  947. </xsl:otherwise>
  948. </xsl:choose>
  949. </xsl:template>
  950. <!-- Get the link text from a topic within the same file as the link. -->
  951. <xsl:template match="*" mode="topicpull:getlinktext-samefile">
  952. <xsl:param name="classval"/>
  953. <xsl:param name="topicid"/>
  954. <xsl:choose>
  955. <xsl:when test="key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/title ')]">
  956. <xsl:variable name="target-text">
  957. <xsl:apply-templates
  958. select="(key('id', $topicid)[contains(@class, $classval)])[1]/*[contains(@class, ' topic/title ')]" mode="text-only"/>
  959. </xsl:variable>
  960. <xsl:value-of select="normalize-space($target-text)"/>
  961. </xsl:when>
  962. <xsl:when test="key('topic', $topicid)">
  963. <xsl:variable name="target-text">
  964. <xsl:apply-templates
  965. select="key('topic', $topicid)[1]/*[contains(@class, ' topic/title ')]" mode="text-only"/>
  966. </xsl:variable>
  967. <xsl:value-of select="normalize-space($target-text)"/>
  968. </xsl:when>
  969. <!--if can't retrieve, output href as linktext, emit message. since href doesn't include file name, no issues with file extension-->
  970. <xsl:otherwise>
  971. <xsl:value-of select="@href"/>
  972. <xsl:apply-templates select="." mode="ditamsg:cannot-retrieve-linktext"/>
  973. </xsl:otherwise>
  974. </xsl:choose>
  975. </xsl:template>
  976. <!-- Get the link text from a topic when the target is just a file. -->
  977. <xsl:template match="*" mode="topicpull:getlinktext-firstinfile">
  978. <xsl:param name="file"/>
  979. <xsl:param name="classval"/>
  980. <xsl:variable name="doc" select="document($file,/)"/>
  981. <xsl:choose>
  982. <xsl:when test="$doc//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/title ')]">
  983. <xsl:variable name="target-text">
  984. <xsl:apply-templates
  985. select="($doc//*[contains(@class, $classval)])[1]/*[contains(@class, ' topic/title ')]" mode="text-only"/>
  986. </xsl:variable>
  987. <xsl:value-of select="normalize-space($target-text)"/>
  988. </xsl:when>
  989. <xsl:when test="$doc//*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]">
  990. <xsl:variable name="target-text">
  991. <xsl:apply-templates
  992. select="$doc//*[contains(@class, ' topic/topic ')][1]/*[contains(@class, ' topic/title ')]" mode="text-only"/>
  993. </xsl:variable>
  994. <xsl:value-of select="normalize-space($target-text)"/>
  995. </xsl:when>
  996. <!-- if can't retrieve, don't create the linktext - defer to the final output process, which will massage the file name-->
  997. <xsl:otherwise>#none#</xsl:otherwise>
  998. </xsl:choose>
  999. </xsl:template>
  1000. <!-- Get the link text from a specific topic within another file. -->
  1001. <xsl:template match="*" mode="topicpull:getlinktext-otherfile">
  1002. <xsl:param name="file"/>
  1003. <xsl:param name="classval"/>
  1004. <xsl:param name="topicid"/>
  1005. <xsl:variable name="doc" select="document($file,/)"/>
  1006. <xsl:for-each select="$doc">
  1007. <xsl:choose>
  1008. <xsl:when test="key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/title ')]">
  1009. <xsl:variable name="target-text">
  1010. <xsl:apply-templates
  1011. select="(key('id', $topicid)[contains(@class, $classval)])[1]/*[contains(@class, ' topic/title ')]" mode="text-only"/>
  1012. </xsl:variable>
  1013. <xsl:value-of select="normalize-space($target-text)"/>
  1014. </xsl:when>
  1015. <xsl:when test="key('topic', $topicid)/*[contains(@class, ' topic/title ')]">
  1016. <xsl:variable name="target-text">
  1017. <xsl:apply-templates
  1018. select="key('topic', $topicid)[1]/*[contains(@class, ' topic/title ')]" mode="text-only"/>
  1019. </xsl:variable>
  1020. <xsl:value-of select="normalize-space($target-text)"/>
  1021. </xsl:when>
  1022. <!-- if can't retrieve, don't create the linktext - defer to the final output process, which will massage the file name-->
  1023. <xsl:otherwise>#none#</xsl:otherwise>
  1024. </xsl:choose>
  1025. </xsl:for-each>
  1026. </xsl:template>
  1027. <!--get linktext for xref to any body elements. Unsure how to make this extensible,
  1028. if a plugin needs to add support for type=step or type=newElement. May need
  1029. to wait for XSLT 2.0 support, with fancier modes? -->
  1030. <xsl:template match="*" mode="topicpull:getlinktext_within-topic">
  1031. <xsl:param name="file">#none#</xsl:param>
  1032. <xsl:param name="topicpos" as="xs:string"/>
  1033. <xsl:param name="classval">#none#</xsl:param>
  1034. <xsl:param name="topicid">#none#</xsl:param>
  1035. <xsl:param name="elemid">#none#</xsl:param>
  1036. <xsl:variable name="doc" select="document($file,/)"/>
  1037. <xsl:variable name="useclassval">
  1038. <xsl:choose>
  1039. <!--if it's a known type we can handle, use type as-is-->
  1040. <xsl:when test=" $classval='/li ' or $classval='/fn ' or $classval='/dlentry ' or $classval='/section ' or $classval='/example ' or $classval='/fig ' or $classval='/figgroup '">
  1041. <!--can be handled as-is-->
  1042. <xsl:value-of select="$classval"/>
  1043. </xsl:when>
  1044. <!--otherwise figure out what it's topic-level equivalent is by looking it up in the target element's class value-->
  1045. <xsl:when test="$topicpos='samefile'">
  1046. <xsl:apply-templates select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]" mode="topicpull:determine_firstclass"/>
  1047. </xsl:when>
  1048. <xsl:when test="$topicpos='otherfile'">
  1049. <xsl:apply-templates select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]" mode="topicpull:determine_firstclass"/>
  1050. </xsl:when>
  1051. <xsl:otherwise>
  1052. <!--don't generate error msg, since will also be attempting retrieval of linktext, and don't want to double-up on error msgs-->
  1053. </xsl:otherwise>
  1054. </xsl:choose>
  1055. </xsl:variable>
  1056. <xsl:choose>
  1057. <!--processing as a list item - this call only happens when the type is not defined locally or was unknown, but was retrieved from the target; when a known type is defined locally, the appropriate template is applied directly-->
  1058. <xsl:when test="@type='li' or $useclassval='/li '">
  1059. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic_li">
  1060. <xsl:with-param name="file" select="$file"/>
  1061. <xsl:with-param name="topicpos" select="$topicpos"/>
  1062. <xsl:with-param name="classval" select="$useclassval"/>
  1063. <xsl:with-param name="topicid" select="$topicid"/>
  1064. <xsl:with-param name="elemid" select="$elemid"/>
  1065. </xsl:apply-templates>
  1066. </xsl:when>
  1067. <!--processing as a footnote - this call only happens when the type is not defined locally or was unknown, but was retrieved from the target; when a known type is defined locally, the appropriate template is applied directly-->
  1068. <xsl:when test="@type='fn' or $useclassval='/fn '">
  1069. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic_fn">
  1070. <xsl:with-param name="file" select="$file"/>
  1071. <xsl:with-param name="topicpos" select="$topicpos"/>
  1072. <xsl:with-param name="classval" select="$useclassval"/>
  1073. <xsl:with-param name="topicid" select="$topicid"/>
  1074. <xsl:with-param name="elemid" select="$elemid"/>
  1075. </xsl:apply-templates>
  1076. </xsl:when>
  1077. <!--processing as a dlentry - this call only happens when the type is not defined locally or was unknown, but was retrieved from the target; when a known type is defined locally, the appropriate template is applied directly-->
  1078. <xsl:when test="@type='dlentry' or $useclassval='/dlentry '">
  1079. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic_dlentry">
  1080. <xsl:with-param name="file" select="$file"/>
  1081. <xsl:with-param name="topicpos" select="$topicpos"/>
  1082. <xsl:with-param name="classval" select="$useclassval"/>
  1083. <xsl:with-param name="topicid" select="$topicid"/>
  1084. <xsl:with-param name="elemid" select="$elemid"/>
  1085. </xsl:apply-templates>
  1086. </xsl:when>
  1087. <!--processing as a table - this call only happens when the type is not defined locally or was unknown, but was retrieved from the target; when a known type is defined locally, the appropriate template is applied directly-->
  1088. <xsl:when test="@type='table' or $useclassval='/table '">
  1089. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic_table">
  1090. <xsl:with-param name="file" select="$file"/>
  1091. <xsl:with-param name="topicpos" select="$topicpos"/>
  1092. <xsl:with-param name="classval" select="$useclassval"/>
  1093. <xsl:with-param name="topicid" select="$topicid"/>
  1094. <xsl:with-param name="elemid" select="$elemid"/>
  1095. </xsl:apply-templates>
  1096. </xsl:when>
  1097. <!--processing as a figure - this call only happens when the type is not defined locally or was unknown, but was retrieved from the target; when a known type is defined locally, the appropriate template is applied directly-->
  1098. <xsl:when test="@type='fig' or $useclassval='/fig '">
  1099. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic_fig">
  1100. <xsl:with-param name="file" select="$file"/>
  1101. <xsl:with-param name="topicpos" select="$topicpos"/>
  1102. <xsl:with-param name="classval" select="$useclassval"/>
  1103. <xsl:with-param name="topicid" select="$topicid"/>
  1104. <xsl:with-param name="elemid" select="$elemid"/>
  1105. </xsl:apply-templates>
  1106. </xsl:when>
  1107. <!--if it's none of the above types, then apply generic processing - for table, fig, etc. - looking for a child title element-->
  1108. <xsl:otherwise>
  1109. <xsl:apply-templates select="." mode="topicpull:getlinktext_within-topic_otherblock">
  1110. <xsl:with-param name="file" select="$file"/>
  1111. <xsl:with-param name="topicpos" select="$topicpos"/>
  1112. <xsl:with-param name="classval" select="$useclassval"/>
  1113. <xsl:with-param name="topicid" select="$topicid"/>
  1114. <xsl:with-param name="elemid" select="$elemid"/>
  1115. </xsl:apply-templates>
  1116. </xsl:otherwise>
  1117. </xsl:choose>
  1118. </xsl:template>
  1119. <!--used to retrieve a topic-level type from the target element - for example,
  1120. if user specifies "step" as the type, this will look up its topic-level
  1121. equivalent - /li - and use that -->
  1122. <xsl:template match="*" mode="topicpull:determine_firstclass">
  1123. <xsl:text>/</xsl:text>
  1124. <xsl:value-of select="substring-before(substring-after(@class,' topic/'),' ')"/>
  1125. <xsl:text> </xsl:text>
  1126. </xsl:template>
  1127. <!-- Get link text for arbitrary block elements inside a topic. Assumes that the
  1128. target element has a title element. -->
  1129. <xsl:template match="*" mode="topicpull:getlinktext_within-topic_otherblock">
  1130. <xsl:param name="file">#none#</xsl:param>
  1131. <xsl:param name="topicpos" as="xs:string"/>
  1132. <xsl:param name="classval">#none#</xsl:param>
  1133. <xsl:param name="topicid">#none#</xsl:param>
  1134. <xsl:param name="elemid">#none#</xsl:param>
  1135. <xsl:variable name="doc" select="document($file,/)"/>
  1136. <xsl:choose>
  1137. <!--look for the target in the same file, and create the linktext if accessible-->
  1138. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]">
  1139. <xsl:variable name="target-text">
  1140. <xsl:apply-templates
  1141. select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]" mode="text-only"/>
  1142. </xsl:variable>
  1143. <xsl:value-of select="normalize-space($target-text)"/>
  1144. </xsl:when>
  1145. <!--look for the target in another file, and create the linktext if accessible-->
  1146. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]">
  1147. <xsl:variable name="target-text">
  1148. <xsl:apply-templates
  1149. select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]" mode="text-only"/>
  1150. </xsl:variable>
  1151. <xsl:value-of select="normalize-space($target-text)"/>
  1152. </xsl:when>
  1153. <!--If there isn't a title ,then process with spectitle -->
  1154. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ] //*[@id=$elemid][contains(@class, $classval)][1][@spectitle]">
  1155. <xsl:variable name="target-text">
  1156. <xsl:value-of select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)][1]/@spectitle"/>
  1157. </xsl:variable>
  1158. <xsl:value-of select="normalize-space($target-text)"/>
  1159. </xsl:when>
  1160. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[contains(@class, $classval) or contains(@class,' topic/related-links ') ][@id=$elemid][1][@spectitle]">
  1161. <xsl:variable name="target-text">
  1162. <xsl:value-of select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)][1]/@spectitle"/>
  1163. </xsl:variable>
  1164. <xsl:value-of select="normalize-space($target-text)"/>
  1165. </xsl:when>
  1166. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)//*[@id = $elemid][1][contains(@class, ' topic/title ')]">
  1167. <xsl:variable name="target-text">
  1168. <xsl:apply-templates select="key('topic', $topicid)//*[@id = $elemid][1][contains(@class, ' topic/title ')]" mode="text-only"/>
  1169. </xsl:variable>
  1170. <xsl:value-of select="normalize-space($target-text)"/>
  1171. </xsl:when>
  1172. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]//*[@id=$elemid][1][contains(@class, ' topic/title ')]">
  1173. <xsl:variable name="target-text">
  1174. <xsl:apply-templates select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]//*[@id=$elemid][1][contains(@class, ' topic/title ')]" mode="text-only"/>
  1175. </xsl:variable>
  1176. <xsl:value-of select="normalize-space($target-text)"/>
  1177. </xsl:when>
  1178. <!-- No title or spectitle; check to see if the element provides generated text -->
  1179. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ] //*[@id=$elemid][contains(@class, $classval)][1]">
  1180. <xsl:variable name="target-text">
  1181. <xsl:apply-templates select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)][1]" mode="topicpull:get_generated_text"/>
  1182. </xsl:variable>
  1183. <xsl:choose>
  1184. <xsl:when test="$target-text!='#none#'"><xsl:value-of select="normalize-space($target-text)"/></xsl:when>
  1185. <xsl:otherwise><xsl:apply-templates select="." mode="topicpull:otherblock-linktext-fallback"/></xsl:otherwise>
  1186. </xsl:choose>
  1187. </xsl:when>
  1188. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[contains(@class, $classval) or contains(@class,' topic/related-links ') ][@id=$elemid][1]">
  1189. <xsl:variable name="target-text">
  1190. <xsl:apply-templates select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ') or contains(@class,' topic/related-links ') ]//*[@id=$elemid][contains(@class, $classval)][1]" mode="topicpull:get_generated_text"/>
  1191. </xsl:variable>
  1192. <xsl:choose>
  1193. <xsl:when test="$target-text!='#none#'"><xsl:value-of select="normalize-space($target-text)"/></xsl:when>
  1194. <xsl:otherwise><xsl:apply-templates select="." mode="topicpull:otherblock-linktext-fallback"/></xsl:otherwise>
  1195. </xsl:choose>
  1196. </xsl:when>
  1197. <xsl:otherwise>
  1198. <xsl:apply-templates select="." mode="topicpull:otherblock-linktext-fallback"/>
  1199. </xsl:otherwise>
  1200. </xsl:choose>
  1201. </xsl:template>
  1202. <!-- Provide a hook for specializations to give default generated text to new elements.
  1203. By default, elements with no generated text return #none#. -->
  1204. <xsl:template match="*" mode="topicpull:get_generated_text">
  1205. <xsl:text>#none#</xsl:text>
  1206. </xsl:template>
  1207. <!--No link text found; use the href, unless it contains .dita, in which case defer to the final output pass to decide what to do with the file extension-->
  1208. <xsl:template match="*" mode="topicpull:otherblock-linktext-fallback">
  1209. <xsl:choose>
  1210. <xsl:when test="starts-with(@href,'#')">
  1211. <xsl:value-of select="@href"/>
  1212. </xsl:when>
  1213. <xsl:when test="not(@format) or @format = 'dita'">#none#</xsl:when>
  1214. <xsl:otherwise>
  1215. <xsl:value-of select="@href"/>
  1216. </xsl:otherwise>
  1217. </xsl:choose>
  1218. <xsl:apply-templates select="." mode="ditamsg:cannot-retrieve-linktext"/>
  1219. </xsl:template>
  1220. <!-- Pull link text for a figure. Uses mode="topicpull:figure-linktext" to output the text. -->
  1221. <xsl:template match="*" mode="topicpull:getlinktext_within-topic_fig">
  1222. <xsl:param name="file">#none#</xsl:param>
  1223. <xsl:param name="topicpos" as="xs:string"/>
  1224. <xsl:param name="classval">#none#</xsl:param>
  1225. <xsl:param name="topicid">#none#</xsl:param>
  1226. <xsl:param name="elemid">#none#</xsl:param>
  1227. <xsl:variable name="doc" select="document($file,/)"/>
  1228. <xsl:choose>
  1229. <!--look for the target in the same file, and create the linktext if accessible-->
  1230. <!-- and look for the target in another file, and create the linktext if accessible-->
  1231. <!-- April 2007: replace manual language test with lang() function -->
  1232. <xsl:when test="($topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1])
  1233. or ($topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1])">
  1234. <xsl:variable name="fig-count-actual">
  1235. <xsl:choose>
  1236. <xsl:when test="$topicpos='samefile'">
  1237. <xsl:apply-templates select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]" mode="topicpull:fignumber"/>
  1238. </xsl:when>
  1239. <xsl:otherwise>
  1240. <xsl:apply-templates select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]" mode="topicpull:fignumber"/>
  1241. </xsl:otherwise>
  1242. </xsl:choose>
  1243. </xsl:variable>
  1244. <xsl:apply-templates select="." mode="topicpull:figure-linktext">
  1245. <xsl:with-param name="figtext"><xsl:call-template name="getVariable"><xsl:with-param name="id" select="'Figure'"/></xsl:call-template></xsl:with-param>
  1246. <xsl:with-param name="figcount" select="$fig-count-actual"/>
  1247. <xsl:with-param name="figtitle">
  1248. <xsl:choose>
  1249. <xsl:when test="$topicpos='samefile'"><xsl:copy-of select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]"/></xsl:when>
  1250. <xsl:otherwise><xsl:copy-of select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]"/></xsl:otherwise>
  1251. </xsl:choose>
  1252. </xsl:with-param>
  1253. </xsl:apply-templates>
  1254. </xsl:when>
  1255. <!--If there isn't a title ,then process with spectitle -->
  1256. <xsl:when test="($topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle])
  1257. or ($topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle])">
  1258. <xsl:variable name="fig-count-actual">
  1259. <xsl:choose>
  1260. <xsl:when test="$topicpos='samefile'">
  1261. <xsl:apply-templates select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle]" mode="topicpull:fignumber"/>
  1262. </xsl:when>
  1263. <xsl:otherwise>
  1264. <xsl:apply-templates select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle]" mode="topicpull:fignumber"/>
  1265. </xsl:otherwise>
  1266. </xsl:choose>
  1267. </xsl:variable>
  1268. <xsl:apply-templates select="." mode="topicpull:figure-linktext">
  1269. <xsl:with-param name="figtext"><xsl:call-template name="getVariable"><xsl:with-param name="id" select="'Figure'"/></xsl:call-template></xsl:with-param>
  1270. <xsl:with-param name="figcount" select="$fig-count-actual"/>
  1271. <xsl:with-param name="figtitle">
  1272. <xsl:choose>
  1273. <xsl:when test="$topicpos='samefile'"><xsl:value-of select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1]/@spectitle"/></xsl:when>
  1274. <xsl:otherwise><xsl:value-of select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1]/@spectitle"/></xsl:otherwise>
  1275. </xsl:choose>
  1276. </xsl:with-param>
  1277. </xsl:apply-templates>
  1278. </xsl:when>
  1279. <xsl:otherwise>
  1280. <xsl:apply-templates select="." mode="topicpull:figure-linktext-fallback"/>
  1281. </xsl:otherwise>
  1282. </xsl:choose>
  1283. </xsl:template>
  1284. <!-- Determine the text for a link to a figure. Currently uses "Figure N". A node set
  1285. containing the figure's <title> element is also passed in, an override may choose
  1286. to use this in the figure's reference text. -->
  1287. <xsl:template match="*" mode="topicpull:figure-linktext">
  1288. <xsl:param name="figtext"/>
  1289. <xsl:param name="figcount"/>
  1290. <xsl:param name="figtitle"/>
  1291. <xsl:choose>
  1292. <xsl:when test="$FIGURELINK='TITLE'">
  1293. <xsl:apply-templates select="$figtitle" mode="text-only"/>
  1294. </xsl:when>
  1295. <xsl:otherwise> <!-- Default: FIGURELINK='NUMBER' -->
  1296. <xsl:value-of select="$figtext"/>
  1297. <xsl:call-template name="getVariable">
  1298. <xsl:with-param name="id" select="'figure-number-separator'"/>
  1299. </xsl:call-template>
  1300. <xsl:value-of select="$figcount"/>
  1301. </xsl:otherwise>
  1302. </xsl:choose>
  1303. </xsl:template>
  1304. <!-- XXX: Remove I18N processing from here and move to transtype specific code -->
  1305. <xsl:template match="*[lang('hu')]" mode="topicpull:figure-linktext">
  1306. <!-- Hungarian: "1. Figure " -->
  1307. <xsl:param name="figtext"/>
  1308. <xsl:param name="figcount"/>
  1309. <xsl:param name="figtitle"/> <!-- Currently unused, but may be picked up by an override -->
  1310. <xsl:choose>
  1311. <xsl:when test="$FIGURELINK='TITLE'">
  1312. <xsl:apply-templates select="$figtitle" mode="text-only"/>
  1313. </xsl:when>
  1314. <xsl:otherwise> <!-- Default: FIGURELINK='NUMBER' -->
  1315. <xsl:value-of select="$figcount"/>
  1316. <xsl:call-template name="getVariable">
  1317. <xsl:with-param name="id" select="'figure-number-separator'"/>
  1318. </xsl:call-template>
  1319. <xsl:value-of select="$figtext"/>
  1320. </xsl:otherwise>
  1321. </xsl:choose>
  1322. </xsl:template>
  1323. <!-- If the figure is unavailable or we're not sure what to do with it, generate fallback text -->
  1324. <xsl:template match="*" mode="topicpull:figure-linktext-fallback">
  1325. <xsl:choose>
  1326. <xsl:when test="starts-with(@href,'#')">
  1327. <xsl:value-of select="@href"/>
  1328. </xsl:when>
  1329. <xsl:when test="not(@format) or @format = 'dita'">#none#</xsl:when>
  1330. <xsl:otherwise>
  1331. <xsl:value-of select="@href"/>
  1332. </xsl:otherwise>
  1333. </xsl:choose>
  1334. <xsl:apply-templates select="." mode="ditamsg:cannot-retrieve-linktext"/>
  1335. </xsl:template>
  1336. <!-- Determine the number of the figure being linked to -->
  1337. <xsl:template match="*[contains(@class,' topic/fig ')]/*[contains(@class,' topic/title ')] | *[contains(@class,' topic/fig ')][@spectitle]" mode="topicpull:fignumber">
  1338. <xsl:call-template name="compute-number">
  1339. <xsl:with-param name="all">
  1340. <xsl:number from="/*" count="key('count.topic.fig','include')" level="any"/>
  1341. </xsl:with-param>
  1342. <xsl:with-param name="except">
  1343. <xsl:number from="/*" count="key('count.topic.fig','exclude')" level="any"/>
  1344. </xsl:with-param>
  1345. </xsl:call-template>
  1346. </xsl:template>
  1347. <!-- Get text for a link to a table. Actual text is generated in template with mode="topicpull:table-linktext" -->
  1348. <xsl:template match="*" mode="topicpull:getlinktext_within-topic_table">
  1349. <xsl:param name="file">#none#</xsl:param>
  1350. <xsl:param name="topicpos" as="xs:string"/>
  1351. <xsl:param name="classval">#none#</xsl:param>
  1352. <xsl:param name="topicid">#none#</xsl:param>
  1353. <xsl:param name="elemid">#none#</xsl:param>
  1354. <xsl:variable name="doc" select="document($file,/)"/>
  1355. <xsl:choose>
  1356. <!--look for the target in the same file, and create the linktext if accessible-->
  1357. <!-- and look for the target in another file, and create the linktext if accessible-->
  1358. <xsl:when test="($topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1])
  1359. or ($topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1])">
  1360. <xsl:variable name="tbl-count-actual">
  1361. <xsl:choose>
  1362. <xsl:when test="$topicpos='samefile'">
  1363. <xsl:apply-templates select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]" mode="topicpull:tblnumber"/>
  1364. </xsl:when>
  1365. <xsl:otherwise>
  1366. <xsl:apply-templates select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]" mode="topicpull:tblnumber"/>
  1367. </xsl:otherwise>
  1368. </xsl:choose>
  1369. </xsl:variable>
  1370. <xsl:apply-templates select="." mode="topicpull:table-linktext">
  1371. <xsl:with-param name="tbltext"><xsl:call-template name="getVariable"><xsl:with-param name="id" select="'Table'"/></xsl:call-template></xsl:with-param>
  1372. <xsl:with-param name="tblcount" select="$tbl-count-actual"/>
  1373. <xsl:with-param name="tbltitle">
  1374. <xsl:choose>
  1375. <xsl:when test="$topicpos='samefile'"><xsl:copy-of select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]"/></xsl:when>
  1376. <xsl:otherwise><xsl:copy-of select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/title ')][1]"/></xsl:otherwise>
  1377. </xsl:choose>
  1378. </xsl:with-param>
  1379. </xsl:apply-templates>
  1380. </xsl:when>
  1381. <!--If there isn't a title ,then process with spectitle -->
  1382. <xsl:when test="($topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle])
  1383. or ($topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle])">
  1384. <xsl:variable name="tbl-count-actual">
  1385. <xsl:choose>
  1386. <xsl:when test="$topicpos='samefile'">
  1387. <xsl:apply-templates select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle]" mode="topicpull:tblnumber"/>
  1388. </xsl:when>
  1389. <xsl:otherwise>
  1390. <xsl:apply-templates select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1][@spectitle]" mode="topicpull:tblnumber"/>
  1391. </xsl:otherwise>
  1392. </xsl:choose>
  1393. </xsl:variable>
  1394. <xsl:apply-templates select="." mode="topicpull:table-linktext">
  1395. <xsl:with-param name="tbltext"><xsl:call-template name="getVariable"><xsl:with-param name="id" select="'Table'"/></xsl:call-template></xsl:with-param>
  1396. <xsl:with-param name="tblcount" select="$tbl-count-actual"/>
  1397. <xsl:with-param name="tbltitle">
  1398. <xsl:choose>
  1399. <xsl:when test="$topicpos='samefile'"><xsl:value-of select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1]/@spectitle"/></xsl:when>
  1400. <xsl:otherwise><xsl:value-of select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)][1]/@spectitle"/></xsl:otherwise>
  1401. </xsl:choose>
  1402. </xsl:with-param>
  1403. </xsl:apply-templates>
  1404. </xsl:when>
  1405. <!--otherwise use the href, unless it contains .dita, in which case defer to the final output pass to decide what to do with the file extension-->
  1406. <xsl:otherwise>
  1407. <xsl:apply-templates select="." mode="topicpull:table-linktext-fallback"/>
  1408. </xsl:otherwise>
  1409. </xsl:choose>
  1410. </xsl:template>
  1411. <!-- Determine the text for a link to a table. Currently uses table title. -->
  1412. <xsl:template match="*" mode="topicpull:table-linktext">
  1413. <xsl:param name="tbltext"/>
  1414. <xsl:param name="tblcount"/>
  1415. <xsl:param name="tbltitle"/> <!-- Currently unused, but may be picked up by an override -->
  1416. <xsl:choose>
  1417. <xsl:when test="$TABLELINK='TITLE'">
  1418. <xsl:apply-templates select="$tbltitle" mode="text-only"/>
  1419. </xsl:when>
  1420. <xsl:otherwise> <!-- Default: TABLELINK='NUMBER' -->
  1421. <xsl:value-of select="$tbltext"/>
  1422. <xsl:call-template name="getVariable">
  1423. <xsl:with-param name="id" select="'figure-number-separator'"/>
  1424. </xsl:call-template>
  1425. <xsl:value-of select="$tblcount"/>
  1426. </xsl:otherwise>
  1427. </xsl:choose>
  1428. </xsl:template>
  1429. <xsl:template match="*[lang('hu')]" mode="topicpull:table-linktext">
  1430. <!-- Hungarian: "1. Table" -->
  1431. <xsl:param name="tbltext"/>
  1432. <xsl:param name="tblcount"/>
  1433. <xsl:param name="tbltitle"/> <!-- Currently unused, but may be picked up by an override -->
  1434. <xsl:choose>
  1435. <xsl:when test="$TABLELINK='TITLE'">
  1436. <xsl:apply-templates select="$tbltitle" mode="text-only"/>
  1437. </xsl:when>
  1438. <xsl:otherwise> <!-- Default: TABLELINK='NUMBER' -->
  1439. <xsl:value-of select="$tblcount"/>
  1440. <xsl:call-template name="getVariable">
  1441. <xsl:with-param name="id" select="'figure-number-separator'"/>
  1442. </xsl:call-template>
  1443. <xsl:value-of select="$tbltext"/>
  1444. </xsl:otherwise>
  1445. </xsl:choose>
  1446. </xsl:template>
  1447. <!-- Fallback text if a table target cannot be found, or there is some other problem -->
  1448. <xsl:template match="*" mode="topicpull:table-linktext-fallback">
  1449. <xsl:choose>
  1450. <xsl:when test="starts-with(@href,'#')">
  1451. <xsl:value-of select="@href"/>
  1452. </xsl:when>
  1453. <xsl:when test="not(@format) or @format = 'dita'">#none#</xsl:when>
  1454. <xsl:otherwise>
  1455. <xsl:value-of select="@href"/>
  1456. </xsl:otherwise>
  1457. </xsl:choose>
  1458. <xsl:apply-templates select="." mode="ditamsg:cannot-retrieve-linktext"/>
  1459. </xsl:template>
  1460. <!-- Determine the number of the table being linked to -->
  1461. <xsl:template match="*[contains(@class,' topic/table ')]/*[contains(@class,' topic/title ')] | *[contains(@class,' topic/table ')][@spectitle]" mode="topicpull:tblnumber">
  1462. <xsl:call-template name="compute-number">
  1463. <xsl:with-param name="all">
  1464. <xsl:number from="/*" count="key('count.topic.table','include')" level="any"/>
  1465. </xsl:with-param>
  1466. <xsl:with-param name="except">
  1467. <xsl:number from="/*" count="key('count.topic.table','exclude')" level="any"/>
  1468. </xsl:with-param>
  1469. </xsl:call-template>
  1470. </xsl:template>
  1471. <!-- Set link text when linking to a list item -->
  1472. <xsl:template match="*" mode="topicpull:getlinktext_within-topic_li">
  1473. <xsl:param name="file">#none#</xsl:param>
  1474. <xsl:param name="topicpos" as="xs:string"/>
  1475. <xsl:param name="classval">#none#</xsl:param>
  1476. <xsl:param name="topicid">#none#</xsl:param>
  1477. <xsl:param name="elemid">#none#</xsl:param>
  1478. <xsl:variable name="doc" select="document($file,/)"/>
  1479. <xsl:choose>
  1480. <!-- If the list item exists, and is in an OL, process it -->
  1481. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[contains(@class,' topic/ol ')]/*[@id=$elemid][contains(@class, $classval)]">
  1482. <xsl:apply-templates mode="topicpull:li-linktext" select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[contains(@class,' topic/ol ')]/*[@id=$elemid][contains(@class, $classval)]"/>
  1483. </xsl:when>
  1484. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[contains(@class,' topic/ol ')]/*[@id=$elemid][contains(@class, $classval)]">
  1485. <xsl:apply-templates mode="topicpull:li-linktext" select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[contains(@class,' topic/ol ')]/*[@id=$elemid][contains(@class, $classval)]"/>
  1486. </xsl:when>
  1487. <!-- If the list item exists, but is in some other kind of list, issue a message -->
  1488. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]">
  1489. <xsl:call-template name="topicpull:referenced-invalid-list-item"/>
  1490. </xsl:when>
  1491. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]">
  1492. <xsl:call-template name="topicpull:referenced-invalid-list-item"/>
  1493. </xsl:when>
  1494. <xsl:otherwise>
  1495. <xsl:choose>
  1496. <xsl:when test="starts-with(@href,'#')">
  1497. <xsl:value-of select="@href"/>
  1498. </xsl:when>
  1499. <xsl:when test="not(@format) or @format = 'dita'">#none#</xsl:when>
  1500. <xsl:otherwise>
  1501. <xsl:value-of select="@href"/>
  1502. </xsl:otherwise>
  1503. </xsl:choose>
  1504. <xsl:apply-templates select="." mode="ditamsg:cannot-retrieve-list-number"/>
  1505. </xsl:otherwise>
  1506. </xsl:choose>
  1507. </xsl:template>
  1508. <!-- Matching the list item, determine the count for this item -->
  1509. <xsl:template match="*[contains(@class,' topic/ol ')]/*[contains(@class,' topic/li ')]" mode="topicpull:li-linktext">
  1510. <xsl:number level="multiple"
  1511. count="*[contains(@class,' topic/ol ')]/*[contains(@class,' topic/li ')]" format="1.a.i.1.a.i.1.a.i"/>
  1512. </xsl:template>
  1513. <!-- Instead of matching an unordered list item, we will call this template; that way
  1514. the error points to the XREF, not to the list item. -->
  1515. <xsl:template name="topicpull:referenced-invalid-list-item">
  1516. <xsl:apply-templates select="." mode="ditamsg:crossref-unordered-listitem"/>
  1517. </xsl:template>
  1518. <!-- Generate link text for a footnote reference -->
  1519. <xsl:template match="*" mode="topicpull:getlinktext_within-topic_fn">
  1520. <xsl:param name="file">#none#</xsl:param>
  1521. <xsl:param name="topicpos" as="xs:string"/>
  1522. <xsl:param name="classval">#none#</xsl:param>
  1523. <xsl:param name="topicid">#none#</xsl:param>
  1524. <xsl:param name="elemid">#none#</xsl:param>
  1525. <xsl:variable name="doc" select="document($file,/)"/>
  1526. <xsl:choose>
  1527. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]">
  1528. <xsl:apply-templates mode="topicpull:fn-linktext" select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]"/>
  1529. </xsl:when>
  1530. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]">
  1531. <xsl:apply-templates mode="topicpull:fn-linktext" select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]"/>
  1532. </xsl:when>
  1533. <xsl:otherwise>
  1534. <xsl:choose>
  1535. <xsl:when test="starts-with(@href,'#')">
  1536. <xsl:value-of select="@href"/>
  1537. </xsl:when>
  1538. <xsl:when test="not(@format) or @format = 'dita'">#none#</xsl:when>
  1539. <xsl:otherwise>
  1540. <xsl:value-of select="@href"/>
  1541. </xsl:otherwise>
  1542. </xsl:choose>
  1543. <xsl:apply-templates select="." mode="ditamsg:cannot-retrieve-footnote-number"/>
  1544. </xsl:otherwise>
  1545. </xsl:choose>
  1546. </xsl:template>
  1547. <xsl:template match="*[contains(@class,' topic/fn ')]" mode="topicpull:fn-linktext">
  1548. <xsl:variable name="fnid">
  1549. <xsl:number from="/" level="any"/>
  1550. </xsl:variable>
  1551. <xsl:variable name="callout">
  1552. <xsl:value-of select="@callout"/>
  1553. </xsl:variable>
  1554. <xsl:variable name="convergedcallout">
  1555. <xsl:choose>
  1556. <xsl:when test="string-length($callout)&gt;0">
  1557. <xsl:value-of select="$callout"/>
  1558. </xsl:when>
  1559. <xsl:otherwise>
  1560. <xsl:value-of select="$fnid"/>
  1561. </xsl:otherwise>
  1562. </xsl:choose>
  1563. </xsl:variable>
  1564. <a name="fnsrc_{$fnid}" href="#fntarg_{$fnid}">
  1565. <sup>
  1566. <xsl:value-of select="$convergedcallout"/>
  1567. </sup>
  1568. </a>
  1569. </xsl:template>
  1570. <!-- Getting text from a dlentry target: use the contents of the term -->
  1571. <xsl:template match="*" mode="topicpull:getlinktext_within-topic_dlentry">
  1572. <xsl:param name="file">#none#</xsl:param>
  1573. <xsl:param name="topicpos" as="xs:string"/>
  1574. <xsl:param name="classval">#none#</xsl:param>
  1575. <xsl:param name="topicid">#none#</xsl:param>
  1576. <xsl:param name="elemid">#none#</xsl:param>
  1577. <xsl:variable name="doc" select="document($file,/)"/>
  1578. <xsl:choose>
  1579. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/dt ')][1]">
  1580. <xsl:variable name="target-text">
  1581. <xsl:apply-templates
  1582. select="key('topic', $topicid)[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/dt ')][1]" mode="text-only"/>
  1583. </xsl:variable>
  1584. <xsl:value-of select="normalize-space($target-text)"/>
  1585. </xsl:when>
  1586. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/dt ')][1]">
  1587. <xsl:variable name="target-text">
  1588. <xsl:apply-templates
  1589. select="($doc//*[contains(@class, ' topic/topic ')][@id=$topicid])[1]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class,' topic/dt ')][1]" mode="text-only"/>
  1590. </xsl:variable>
  1591. <xsl:value-of select="normalize-space($target-text)"/>
  1592. </xsl:when>
  1593. <xsl:otherwise>
  1594. <xsl:choose>
  1595. <xsl:when test="starts-with(@href,'#')">
  1596. <xsl:value-of select="@href"/>
  1597. </xsl:when>
  1598. <xsl:when test="not(@format) or @format = 'dita'">#none#</xsl:when>
  1599. <xsl:otherwise>
  1600. <xsl:value-of select="@href"/>
  1601. </xsl:otherwise>
  1602. </xsl:choose>
  1603. <xsl:apply-templates select="." mode="ditamsg:cannot-find-dlentry-target"/>
  1604. </xsl:otherwise>
  1605. </xsl:choose>
  1606. </xsl:template>
  1607. <!--getting the shortdesc for a link; called from main mode template for link/xref,
  1608. only after conditions such as scope and format have been tested and a text pull
  1609. has been determined to be appropriate-->
  1610. <xsl:template match="*" mode="topicpull:getshortdesc">
  1611. <xsl:param name="file">#none#</xsl:param>
  1612. <xsl:param name="topicpos" as="xs:string"/>
  1613. <xsl:param name="classval">#none#</xsl:param>
  1614. <xsl:param name="topicid">#none#</xsl:param>
  1615. <xsl:param name="elemid">#none#</xsl:param>
  1616. <xsl:choose>
  1617. <xsl:when test="$elemid!='#none#'">
  1618. <xsl:apply-templates select="." mode="topicpull:getshortdesc_element">
  1619. <xsl:with-param name="file" select="$file"/>
  1620. <xsl:with-param name="topicpos" select="$topicpos"/>
  1621. <xsl:with-param name="classval" select="$classval"/>
  1622. <xsl:with-param name="topicid" select="$topicid"/>
  1623. <xsl:with-param name="elemid" select="$elemid"/>
  1624. </xsl:apply-templates>
  1625. </xsl:when>
  1626. <xsl:when test="$topicpos='samefile'">
  1627. <xsl:apply-templates select="." mode="topicpull:getshortdesc_samefile">
  1628. <xsl:with-param name="classval" select="$classval"/>
  1629. <xsl:with-param name="topicid" select="$topicid"/>
  1630. </xsl:apply-templates>
  1631. </xsl:when>
  1632. <xsl:when test="$topicpos='firstinfile'">
  1633. <xsl:apply-templates select="." mode="topicpull:getshortdesc_firstinfile">
  1634. <xsl:with-param name="file" select="$file"/>
  1635. <xsl:with-param name="classval" select="$classval"/>
  1636. </xsl:apply-templates>
  1637. </xsl:when>
  1638. <xsl:when test="$topicpos='otherfile'">
  1639. <xsl:apply-templates select="." mode="topicpull:getshortdesc_otherfile">
  1640. <xsl:with-param name="file" select="$file"/>
  1641. <xsl:with-param name="classval" select="$classval"/>
  1642. <xsl:with-param name="topicid" select="$topicid"/>
  1643. </xsl:apply-templates>
  1644. </xsl:when>
  1645. </xsl:choose>
  1646. </xsl:template>
  1647. <!-- Get the short description for a non-topic element. Search for an element with the matching
  1648. correct class value and matching ID, inside the topic with the correct ID. If found, use
  1649. the local <desc> element. If not found, do not create a short description. -->
  1650. <xsl:template match="*" mode="topicpull:getshortdesc_element">
  1651. <xsl:param name="file">#none#</xsl:param>
  1652. <xsl:param name="topicpos" as="xs:string"/>
  1653. <xsl:param name="classval">#none#</xsl:param>
  1654. <xsl:param name="topicid">#none#</xsl:param>
  1655. <xsl:param name="elemid">#none#</xsl:param>
  1656. <xsl:variable name="doc" select="document($file,/)"/>
  1657. <xsl:choose>
  1658. <xsl:when test="$topicpos='samefile' and key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class, ' topic/desc ')]">
  1659. <xsl:apply-templates select="key('topic', $topicid)/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class, ' topic/desc ')]" mode="copy-desc-contents"/>
  1660. </xsl:when>
  1661. <xsl:when test="$topicpos='otherfile' and $doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class, ' topic/desc ')]">
  1662. <xsl:apply-templates select="$doc//*[contains(@class, ' topic/topic ')][@id=$topicid]/*[contains(@class,' topic/body ') or contains(@class,' topic/abstract ')]//*[@id=$elemid][contains(@class, $classval)]/*[contains(@class, ' topic/desc ')]" mode="copy-desc-contents"/>
  1663. </xsl:when>
  1664. <xsl:otherwise>#none#</xsl:otherwise>
  1665. </xsl:choose>
  1666. </xsl:template>
  1667. <!-- Get the shortdesc for a topic that is in the same file -->
  1668. <xsl:template match="*" mode="topicpull:getshortdesc_samefile">
  1669. <xsl:param name="classval">#none#</xsl:param>
  1670. <xsl:param name="topicid">#none#</xsl:param>
  1671. <xsl:choose>
  1672. <!-- Check for topic with matching class and matching ID -->
  1673. <xsl:when test="key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/shortdesc ')] |
  1674. key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]">
  1675. <xsl:apply-templates select="key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/shortdesc ')] |
  1676. key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc" />
  1677. </xsl:when>
  1678. <!-- Check for topic with matching ID -->
  1679. <xsl:when test="key('topic', $topicid)/*[contains(@class, ' topic/shortdesc ')] |
  1680. key('topic', $topicid)/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]">
  1681. <xsl:apply-templates select="key('topic', $topicid)/*[contains(@class, ' topic/shortdesc ')] |
  1682. key('topic', $topicid)/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc"/>
  1683. </xsl:when>
  1684. <!-- Remove previously existing general tests. If a specific topic is the target, shortdesc should not be pulled from another. -->
  1685. <xsl:otherwise>
  1686. <xsl:text>#none#</xsl:text>
  1687. </xsl:otherwise>
  1688. </xsl:choose>
  1689. </xsl:template>
  1690. <!-- Get the shortdesc from a topic, when the topic is a file name -->
  1691. <xsl:template match="*" mode="topicpull:getshortdesc_firstinfile">
  1692. <xsl:param name="file">#none#</xsl:param>
  1693. <xsl:param name="classval">#none#</xsl:param>
  1694. <xsl:variable name="doc" select="document($file,/)"/>
  1695. <xsl:choose>
  1696. <xsl:when test="$doc//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/shortdesc ')] |
  1697. $doc//*[contains(@class, $classval)][1]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]">
  1698. <xsl:apply-templates select="($doc//*[contains(@class, $classval)])[1]/*[contains(@class, ' topic/shortdesc ')] |
  1699. ($doc//*[contains(@class, $classval)])[1]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc"/>
  1700. </xsl:when>
  1701. <xsl:when test="$doc//*[contains(@class, ' topic/topic ')][1]/*[contains(@class, ' topic/shortdesc ')] |
  1702. $doc//*[contains(@class, ' topic/topic ')][1]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]">
  1703. <xsl:apply-templates select="($doc//*[contains(@class, ' topic/topic ')])[1]/*[contains(@class, ' topic/shortdesc ')] |
  1704. ($doc//*[contains(@class, ' topic/topic ')])[1]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc"/>
  1705. </xsl:when>
  1706. <xsl:otherwise>
  1707. <xsl:text>#none#</xsl:text>
  1708. </xsl:otherwise>
  1709. </xsl:choose>
  1710. </xsl:template>
  1711. <!-- Get the shortdesc from a specific topic in another file -->
  1712. <xsl:template match="*" mode="topicpull:getshortdesc_otherfile">
  1713. <xsl:param name="file">#none#</xsl:param>
  1714. <xsl:param name="classval">#none#</xsl:param>
  1715. <xsl:param name="topicid">#none#</xsl:param>
  1716. <xsl:variable name="doc" select="document($file,/)"/>
  1717. <xsl:for-each select="$doc">
  1718. <xsl:choose>
  1719. <xsl:when test="key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/shortdesc ')] |
  1720. key('id', $topicid)[contains(@class, $classval)]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]">
  1721. <xsl:apply-templates select="(key('id', $topicid)[contains(@class, $classval)])[1]/*[contains(@class, ' topic/shortdesc ')] |
  1722. (key('id', $topicid)[contains(@class, $classval)])[1]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc"/>
  1723. </xsl:when>
  1724. <xsl:when test="key('topic', $topicid)/*[contains(@class, ' topic/shortdesc ')] |
  1725. key('topic', $topicid)/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]">
  1726. <xsl:apply-templates select="key('topic', $topicid)[1]/*[contains(@class, ' topic/shortdesc ')] |
  1727. key('topic', $topicid)[1]/*[contains(@class, ' topic/abstract ')]/*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc"/>
  1728. </xsl:when>
  1729. <xsl:when test="key('id', $topicid)[contains(@class, $classval)]//*[contains(@class, ' topic/shortdesc ')]">
  1730. <xsl:apply-templates select="(key('id', $topicid)[contains(@class, $classval)])[1]//*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc" />
  1731. </xsl:when>
  1732. <xsl:when
  1733. test="key('topic', $topicid)//*[contains(@class, ' topic/shortdesc ')]">
  1734. <xsl:apply-templates select="key('topic', $topicid)[1]//*[contains(@class, ' topic/shortdesc ')]" mode="copy-shortdesc" />
  1735. </xsl:when>
  1736. <xsl:otherwise>
  1737. <xsl:text>#none#</xsl:text>
  1738. </xsl:otherwise>
  1739. </xsl:choose>
  1740. </xsl:for-each>
  1741. </xsl:template>
  1742. <xsl:template match="*|text()|processing-instruction()" mode="text-only">
  1743. <!-- Redirect to common dita-ot module -->
  1744. <xsl:apply-templates select="." mode="dita-ot:text-only"/>
  1745. </xsl:template>
  1746. <xsl:template match="*|@*|comment()|processing-instruction()|text()">
  1747. <xsl:copy>
  1748. <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
  1749. </xsl:copy>
  1750. </xsl:template>
  1751. <xsl:template match="*[contains(@class,' topic/xref ')]" mode="copy-shortdesc">
  1752. <xsl:choose>
  1753. <xsl:when test="not(@href) or @scope='peer' or @scope='external'">
  1754. <xsl:copy>
  1755. <xsl:apply-templates select="@*|text()|*" mode="copy-shortdesc" />
  1756. </xsl:copy>
  1757. </xsl:when>
  1758. <xsl:when test="@format and not(@format='dita')">
  1759. <xsl:copy>
  1760. <xsl:apply-templates select="@*|text()|*" mode="copy-shortdesc" />
  1761. </xsl:copy>
  1762. </xsl:when>
  1763. <xsl:when test="not(contains(@href,'/'))"><!-- May be DITA, but in the same directory -->
  1764. <xsl:copy>
  1765. <xsl:apply-templates select="@*|text()|*" mode="copy-shortdesc" />
  1766. </xsl:copy>
  1767. </xsl:when>
  1768. <xsl:when test="text()|*[not(contains(@class,' topic/desc '))]">
  1769. <xsl:apply-templates select="*[not(contains(@class,' topic/desc '))]|text()|comment()|processing-instruction()" mode="copy-shortdesc" />
  1770. </xsl:when>
  1771. <xsl:otherwise>
  1772. <xsl:text>***</xsl:text><!-- go get the target text -->
  1773. </xsl:otherwise>
  1774. </xsl:choose>
  1775. </xsl:template>
  1776. <xsl:template match="text()" mode="copy-shortdesc">
  1777. <xsl:value-of select="translate(.,'&#xA;',' ')" />
  1778. </xsl:template>
  1779. <xsl:template match="*[contains(@class,' topic/desc ')]" mode="copy-desc-contents">
  1780. <!-- For desc: match a desc, then switch to matching shortdesc rules -->
  1781. <xsl:apply-templates select="*|text()|comment()|processing-instruction()" mode="copy-shortdesc"/>
  1782. </xsl:template>
  1783. <xsl:template match="*[contains(@class,' topic/shortdesc ')]" mode="copy-shortdesc">
  1784. <xsl:if test="preceding-sibling::*[contains(@class,' topic/shortdesc ')]">
  1785. <!-- In an abstract, and this is not the first -->
  1786. <xsl:text> </xsl:text>
  1787. </xsl:if>
  1788. <xsl:apply-templates select="*|text()|comment()|processing-instruction()" mode="copy-shortdesc" />
  1789. </xsl:template>
  1790. <xsl:template match="@id" mode="copy-shortdesc" />
  1791. <xsl:template match="*[contains(@class,' topic/indexterm ')]" mode="copy-shortdesc" />
  1792. <xsl:template match="*[contains(@class,' topic/draft-comment ') or contains(@class,' topic/required-cleanup ')]" mode="copy-shortdesc"/>
  1793. <xsl:template match="*|@*|processing-instruction()" mode="copy-shortdesc">
  1794. <xsl:copy>
  1795. <xsl:apply-templates select="@*|text()|*|processing-instruction()" mode="copy-shortdesc" />
  1796. </xsl:copy>
  1797. </xsl:template>
  1798. <!-- Used to determine the number of figures and tables; could be used for other functions as well. -->
  1799. <xsl:template name="compute-number">
  1800. <xsl:param name="except"/>
  1801. <xsl:param name="all"/>
  1802. <xsl:choose>
  1803. <xsl:when test="$except != ''">
  1804. <xsl:value-of select="number($all) - number($except)"/>
  1805. </xsl:when>
  1806. <xsl:otherwise>
  1807. <xsl:value-of select="$all"/>
  1808. </xsl:otherwise>
  1809. </xsl:choose>
  1810. </xsl:template>
  1811. <!-- Make it easy to override messages. If a product wishes to change or hide
  1812. specific messages, it can override these templates. Longer term, it would
  1813. be good to move messages from each XSL file into a common location. -->
  1814. <!-- Deprecated -->
  1815. <xsl:template match="*" mode="ditamsg:unknown-extension">
  1816. <xsl:call-template name="output-message">
  1817. <xsl:with-param name="id" select="'DOTX006E'"/>
  1818. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  1819. </xsl:call-template>
  1820. </xsl:template>
  1821. <xsl:template match="*" mode="ditamsg:empty-href">
  1822. <xsl:call-template name="output-message">
  1823. <xsl:with-param name="id" select="'DOTX017E'"/>
  1824. </xsl:call-template>
  1825. </xsl:template>
  1826. <xsl:template match="*" mode="ditamsg:missing-href">
  1827. <xsl:call-template name="output-message">
  1828. <xsl:with-param name="id" select="'DOTX028E'"/>
  1829. </xsl:call-template>
  1830. </xsl:template>
  1831. <xsl:template match="*" mode="ditamsg:type-attribute-not-specific">
  1832. <xsl:param name="elem-name" select="name()"/>
  1833. <xsl:param name="targetting"/>
  1834. <xsl:param name="type"/>
  1835. <xsl:param name="actual-name"/>
  1836. <xsl:call-template name="output-message">
  1837. <xsl:with-param name="id" select="'DOTX029I'"/>
  1838. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$elem-name"/>;%2=<xsl:value-of select="$targetting"/>;%3=<xsl:value-of select="$type"/>;%4=<xsl:value-of select="$actual-name"/></xsl:with-param>
  1839. </xsl:call-template>
  1840. </xsl:template>
  1841. <xsl:template match="*" mode="ditamsg:type-attribute-incorrect">
  1842. <xsl:param name="elem-name" select="name()"/>
  1843. <xsl:param name="targetting"/>
  1844. <xsl:param name="type"/>
  1845. <xsl:param name="actual-name"/>
  1846. <xsl:call-template name="output-message">
  1847. <xsl:with-param name="id" select="'DOTX030W'"/>
  1848. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$elem-name"/>;%2=<xsl:value-of select="$targetting"/>;%3=<xsl:value-of select="$type"/>;%4=<xsl:value-of select="$actual-name"/></xsl:with-param>
  1849. </xsl:call-template>
  1850. </xsl:template>
  1851. <xsl:template match="*" mode="ditamsg:missing-href-target">
  1852. <xsl:param name="file"/>
  1853. <xsl:choose>
  1854. <xsl:when test="$ONLYTOPICINMAP='true'">
  1855. <xsl:call-template name="output-message">
  1856. <xsl:with-param name="id" select="'DOTX056W'"/>
  1857. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$file"/></xsl:with-param>
  1858. </xsl:call-template>
  1859. </xsl:when>
  1860. <xsl:otherwise>
  1861. <xsl:call-template name="output-message">
  1862. <xsl:with-param name="id" select="'DOTX031E'"/>
  1863. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$file"/></xsl:with-param>
  1864. </xsl:call-template>
  1865. </xsl:otherwise>
  1866. </xsl:choose>
  1867. </xsl:template>
  1868. <xsl:template match="*" mode="ditamsg:cannot-retrieve-linktext">
  1869. <xsl:call-template name="output-message">
  1870. <xsl:with-param name="id" select="'DOTX032E'"/>
  1871. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  1872. </xsl:call-template>
  1873. </xsl:template>
  1874. <xsl:template match="*" mode="ditamsg:cannot-retrieve-list-number">
  1875. <xsl:call-template name="output-message">
  1876. <xsl:with-param name="id" select="'DOTX033E'"/>
  1877. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  1878. </xsl:call-template>
  1879. </xsl:template>
  1880. <xsl:template match="*" mode="ditamsg:crossref-unordered-listitem">
  1881. <xsl:call-template name="output-message">
  1882. <xsl:with-param name="id" select="'DOTX034E'"/>
  1883. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  1884. </xsl:call-template>
  1885. </xsl:template>
  1886. <xsl:template match="*" mode="ditamsg:cannot-retrieve-footnote-number">
  1887. <xsl:call-template name="output-message">
  1888. <xsl:with-param name="id" select="'DOTX035E'"/>
  1889. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  1890. </xsl:call-template>
  1891. </xsl:template>
  1892. <xsl:template match="*" mode="ditamsg:cannot-find-dlentry-target">
  1893. <xsl:call-template name="output-message">
  1894. <xsl:with-param name="id" select="'DOTX036E'"/>
  1895. <xsl:with-param name="msgparams">%1=<xsl:value-of select="@href"/></xsl:with-param>
  1896. </xsl:call-template>
  1897. </xsl:template>
  1898. <xsl:template match="*|@*|text()|comment()|processing-instruction()" mode="specialize-foreign-unknown">
  1899. <xsl:copy>
  1900. <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" mode="specialize-foreign-unknown"/>
  1901. </xsl:copy>
  1902. </xsl:template>
  1903. <!-- Added for RFE 1367897. Ensure that if a value was passed in from the map,
  1904. we respect that value, otherwise, use the value determined by this program. -->
  1905. <xsl:template match="*" mode="topicpull:add-gentext-PI">
  1906. <xsl:choose>
  1907. <xsl:when test="processing-instruction()[name()='ditaot'][.='usertext' or .='gentext']">
  1908. <xsl:copy-of select="processing-instruction()[name()='ditaot'][.='usertext' or .='gentext']"/>
  1909. </xsl:when>
  1910. <xsl:otherwise>
  1911. <xsl:processing-instruction name="ditaot">gentext</xsl:processing-instruction>
  1912. </xsl:otherwise>
  1913. </xsl:choose>
  1914. </xsl:template>
  1915. <xsl:template match="*" mode="topicpull:add-usertext-PI">
  1916. <xsl:choose>
  1917. <xsl:when test="processing-instruction()[name()='ditaot'][.='usertext' or .='gentext']">
  1918. <xsl:copy-of select="processing-instruction()[name()='ditaot'][.='usertext' or .='gentext']"/>
  1919. </xsl:when>
  1920. <xsl:otherwise>
  1921. <xsl:processing-instruction name="ditaot">usertext</xsl:processing-instruction>
  1922. </xsl:otherwise>
  1923. </xsl:choose>
  1924. </xsl:template>
  1925. <!-- Added for RFE 3001750. -->
  1926. <xsl:template match="*" mode="topicpull:add-genshortdesc-PI">
  1927. <xsl:choose>
  1928. <xsl:when test="processing-instruction()[name()='ditaot'][.='usershortdesc' or .='genshortdesc']">
  1929. <xsl:copy-of select="processing-instruction()[name()='ditaot'][.='usershortdesc' or .='genshortdesc']"/>
  1930. </xsl:when>
  1931. <xsl:otherwise>
  1932. <xsl:processing-instruction name="ditaot">genshortdesc</xsl:processing-instruction>
  1933. </xsl:otherwise>
  1934. </xsl:choose>
  1935. </xsl:template>
  1936. <xsl:template match="*" mode="topicpull:add-usershortdesc-PI">
  1937. <xsl:choose>
  1938. <xsl:when test="processing-instruction()[name()='ditaot'][.='usershortdesc' or .='genshortdesc']">
  1939. <xsl:copy-of select="processing-instruction()[name()='ditaot'][.='usershortdesc' or .='genshortdesc']"/>
  1940. </xsl:when>
  1941. <xsl:otherwise>
  1942. <xsl:processing-instruction name="ditaot">usershortdesc</xsl:processing-instruction>
  1943. </xsl:otherwise>
  1944. </xsl:choose>
  1945. </xsl:template>
  1946. </xsl:stylesheet>