topicpull-pr-d.xsl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?xml version="1.0"?>
  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. 2007 All Rights Reserved. -->
  6. <xsl:stylesheet version="2.0"
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:topicpull="http://dita-ot.sourceforge.net/ns/200704/topicpull"
  9. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  10. exclude-result-prefixes="topicpull ditamsg">
  11. <xsl:template match="*[contains(@class, ' pr-d/fragref ')]">
  12. <xsl:if test="@href=''">
  13. <xsl:apply-templates select="." mode="ditamsg:empty-href"/>
  14. </xsl:if>
  15. <xsl:choose>
  16. <!-- fragref cannot allow desc, so no need to check for it -->
  17. <xsl:when test="text()|*">
  18. <xsl:copy>
  19. <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
  20. </xsl:copy>
  21. </xsl:when>
  22. <xsl:when test="@href and not(@href='')">
  23. <xsl:copy>
  24. <xsl:apply-templates select="@*"/>
  25. <!--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)-->
  26. <xsl:variable name="type">
  27. <xsl:choose>
  28. <xsl:when test="@type">
  29. <xsl:value-of select="@type"/>
  30. </xsl:when>
  31. <xsl:otherwise>#none#</xsl:otherwise>
  32. </xsl:choose>
  33. </xsl:variable>
  34. <xsl:variable name="format">
  35. <xsl:choose>
  36. <xsl:when test="@format">
  37. <xsl:value-of select="@format"/>
  38. </xsl:when>
  39. <xsl:otherwise>#none#</xsl:otherwise>
  40. </xsl:choose>
  41. </xsl:variable>
  42. <xsl:variable name="scope">
  43. <xsl:choose>
  44. <xsl:when test="@scope">
  45. <xsl:value-of select="@scope"/>
  46. </xsl:when>
  47. <xsl:otherwise>#none#</xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:variable>
  50. <!--grab type, text and metadata, as long there's an href to grab from, otherwise error-->
  51. <xsl:apply-templates select="." mode="topicpull:get-stuff">
  52. <xsl:with-param name="localtype" select="$type"/>
  53. <xsl:with-param name="scope" select="$scope"/>
  54. <xsl:with-param name="format" select="$format"/>
  55. </xsl:apply-templates>
  56. </xsl:copy>
  57. </xsl:when>
  58. <xsl:otherwise>
  59. <xsl:apply-templates select="." mode="ditamsg:missing-href"/>
  60. </xsl:otherwise>
  61. </xsl:choose>
  62. </xsl:template>
  63. <!-- Override the rule for fragref, so that it does not retrieve <desc> -->
  64. <xsl:template match="*[contains(@class,' pr-d/fragref ')]" mode="topicpull:get-stuff">
  65. <xsl:param name="localtype">#none#</xsl:param>
  66. <xsl:param name="scope">#none#</xsl:param>
  67. <xsl:param name="format">#none#</xsl:param>
  68. <!--the file name of the target, if any-->
  69. <xsl:variable name="file"><xsl:apply-templates select="." mode="topicpull:get-stuff_file"/></xsl:variable>
  70. <!--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-->
  71. <xsl:variable name="topicpos"><xsl:apply-templates select="." mode="topicpull:get-stuff_topicpos"/></xsl:variable>
  72. <xsl:apply-templates select="." mode="topicpull:get-stuff_verify-target-present">
  73. <xsl:with-param name="topicpos" select="$topicpos"/>
  74. <xsl:with-param name="scope" select="$scope"/>
  75. <xsl:with-param name="format" select="$format"/>
  76. <xsl:with-param name="file" select="$file"/>
  77. </xsl:apply-templates>
  78. <!--the id of the target topic-->
  79. <xsl:variable name="topicid">
  80. <xsl:apply-templates select="." mode="topicpull:get-stuff_topicid"/>
  81. </xsl:variable>
  82. <!--the id of the target element, if any-->
  83. <xsl:variable name="elemid">
  84. <xsl:apply-templates select="." mode="topicpull:get-stuff_elemid"/>
  85. </xsl:variable>
  86. <!--type - grab type from target, if not defined locally -->
  87. <xsl:variable name="type">
  88. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-type">
  89. <xsl:with-param name="localtype" select="$localtype"/>
  90. <xsl:with-param name="scope" select="$scope"/>
  91. <xsl:with-param name="format" select="$format"/>
  92. <xsl:with-param name="topicpos" select="$topicpos"/>
  93. <xsl:with-param name="file" select="$file"/>
  94. <xsl:with-param name="topicid" select="$topicid"/>
  95. <xsl:with-param name="elemid" select="$elemid"/>
  96. </xsl:apply-templates>
  97. </xsl:variable>
  98. <!--now, create the type attribute, if the type attribute didn't exist locally but was retrieved successfully-->
  99. <xsl:if test="$localtype='#none#' and not($type='#none#')">
  100. <xsl:attribute name="type"><xsl:value-of select="$type"/></xsl:attribute>
  101. </xsl:if>
  102. <!-- Verify that the type was correct, if specified locally, and DITA target is available -->
  103. <xsl:apply-templates select="." mode="topicpull:get-stuff_verify-type">
  104. <xsl:with-param name="localtype" select="$localtype"/>
  105. <xsl:with-param name="scope" select="$scope"/>
  106. <xsl:with-param name="format" select="$format"/>
  107. <xsl:with-param name="topicpos" select="$topicpos"/>
  108. <xsl:with-param name="file" select="$file"/>
  109. <xsl:with-param name="topicid" select="$topicid"/>
  110. <xsl:with-param name="elemid" select="$elemid"/>
  111. </xsl:apply-templates>
  112. <!--create class value string implied by the link's type, used for comparison with class strings in the target topic for validation-->
  113. <xsl:variable name="classval">
  114. <xsl:apply-templates select="." mode="topicpull:get-stuff_classval"><xsl:with-param name="type" select="$type"/></xsl:apply-templates>
  115. </xsl:variable>
  116. <!--linktext-->
  117. <xsl:apply-templates select="." mode="topicpull:get-stuff_get-linktext">
  118. <xsl:with-param name="type" select="$type"/>
  119. <xsl:with-param name="scope" select="$scope"/>
  120. <xsl:with-param name="format" select="$format"/>
  121. <xsl:with-param name="topicpos" select="$topicpos"/>
  122. <xsl:with-param name="file" select="$file"/>
  123. <xsl:with-param name="topicid" select="$topicid"/>
  124. <xsl:with-param name="elemid" select="$elemid"/>
  125. <xsl:with-param name="classval" select="$classval"/>
  126. </xsl:apply-templates>
  127. </xsl:template>
  128. </xsl:stylesheet>