output-message.xsl 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. Standard error message template for DITA processing in XSL. This
  8. file should be included by any XSL program that uses the standard
  9. message template. To include this file, you will need the following
  10. two commands in your XSL:
  11. <xsl:include href="output-message.xsl"/> - Place with other included files
  12. <xsl:variable name="msgprefix">DOTX</xsl:variable> - Place with other variables
  13. The template takes in the following parameters:
  14. - msg = the message to print in the log; default=***
  15. - msgcat = message category, default is read from $msgprefix
  16. - msgnum = the message number (3 digits); default=000
  17. - msgsev = the severity (I, W, E, or F); default=I (Informational)
  18. -->
  19. <xsl:stylesheet version="2.0"
  20. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  21. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  22. exclude-result-prefixes="xs">
  23. <xsl:template name="output-message">
  24. <xsl:param name="ctx" select="." tunnel="yes"/>
  25. <xsl:param name="msg" select="'***'"/>
  26. <!-- Deprecated since 2.3 -->
  27. <xsl:param name="msgcat" select="$msgprefix"/>
  28. <!-- Deprecated since 2.3 -->
  29. <xsl:param name="msgnum" select="'000'"/>
  30. <!-- Deprecated since 2.3 -->
  31. <xsl:param name="msgsev" select="'I'"/>
  32. <xsl:param name="msgparams" select="''"/>
  33. <xsl:param name="id" as="xs:string">
  34. <xsl:call-template name="output-message">
  35. <xsl:with-param name="id" select="'DOTX071W'"/>
  36. <xsl:with-param name="msgparams">%1=msgnum;%2=output-message;%3=id</xsl:with-param>
  37. </xsl:call-template>
  38. <xsl:value-of select="concat($msgcat, $msgnum, $msgsev)"/>
  39. </xsl:param>
  40. <xsl:variable name="msgcontent">
  41. <xsl:choose>
  42. <xsl:when test="$msg != '***'">
  43. <xsl:value-of select="$msg"/>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:variable name="msgdoc" select="document('plugin:org.dita.base:resources/messages.xml')"/>
  47. <xsl:apply-templates select="$msgdoc/messages/message[@id = $id]" mode="get-message-content">
  48. <xsl:with-param name="params" select="$msgparams"/>
  49. </xsl:apply-templates>
  50. </xsl:otherwise>
  51. </xsl:choose>
  52. </xsl:variable>
  53. <xsl:variable name="localclass" select="@class"/>
  54. <xsl:variable name="xtrf" select="$ctx/@xtrf" as="attribute(xtrf)?"/>
  55. <xsl:variable name="xtrc" select="$ctx/@xtrc" as="attribute(xtrc)?"/>
  56. <xsl:variable name="debugloc">
  57. <xsl:if test="$xtrf | $xtrc">
  58. <xsl:if test="$xtrf">
  59. <xsl:value-of select="$xtrf"/>
  60. </xsl:if>
  61. <xsl:if test="$xtrf and $xtrc">
  62. <xsl:text>:</xsl:text>
  63. </xsl:if>
  64. <xsl:if test="$xtrc">
  65. <xsl:value-of select="if (contains($xtrc, ';')) then substring-after($xtrc, ';') else $xtrc"/>
  66. </xsl:if>
  67. <xsl:text>: </xsl:text>
  68. </xsl:if>
  69. </xsl:variable>
  70. <xsl:variable name="m">
  71. <xsl:if test="normalize-space($debugloc)">
  72. <xsl:value-of select="$debugloc"/>
  73. </xsl:if>
  74. <xsl:value-of select="$msgcontent"/>
  75. </xsl:variable>
  76. <xsl:choose>
  77. <xsl:when test="$msgsev = 'F'">
  78. <xsl:message terminate="yes">
  79. <xsl:value-of select="$m"/>
  80. </xsl:message>
  81. </xsl:when>
  82. <xsl:otherwise>
  83. <xsl:message>
  84. <xsl:value-of select="$m"/>
  85. </xsl:message>
  86. </xsl:otherwise>
  87. </xsl:choose>
  88. </xsl:template>
  89. <xsl:template match="message" mode="get-message-content">
  90. <xsl:param name="params"/>
  91. <xsl:variable name="reason" select="reason/text()"/>
  92. <xsl:variable name="response" select="response/text()"/>
  93. <xsl:variable name="messageType" select="@type"/>
  94. <xsl:text>[</xsl:text><xsl:value-of select="@id"/><xsl:text>]</xsl:text>
  95. <xsl:text>[</xsl:text><xsl:value-of select="@type"/><xsl:text>]</xsl:text>
  96. <xsl:text>: </xsl:text>
  97. <xsl:call-template name="replaceParams">
  98. <xsl:with-param name="string" select="$reason"/>
  99. <xsl:with-param name="params" select="$params"/>
  100. </xsl:call-template>
  101. <xsl:text> </xsl:text>
  102. <xsl:call-template name="replaceParams">
  103. <xsl:with-param name="string" select="$response"/>
  104. <xsl:with-param name="params" select="$params"/>
  105. </xsl:call-template>
  106. </xsl:template>
  107. <xsl:template name="replaceParams">
  108. <xsl:param name="string"/>
  109. <xsl:param name="params"/>
  110. <xsl:choose>
  111. <xsl:when test="contains($params, ';')">
  112. <xsl:variable name="param" select="substring-before($params, ';')"/>
  113. <xsl:variable name="newString">
  114. <xsl:call-template name="replaceString">
  115. <xsl:with-param name="string" select="$string"/>
  116. <xsl:with-param name="match" select="substring-before($param, '=')"/>
  117. <xsl:with-param name="replacement" select="substring-after($param, '=')"/>
  118. </xsl:call-template>
  119. </xsl:variable>
  120. <xsl:call-template name="replaceParams">
  121. <xsl:with-param name="string" select="$newString"/>
  122. <xsl:with-param name="params" select="substring-after($params, ';')"/>
  123. </xsl:call-template>
  124. </xsl:when>
  125. <xsl:when test="contains($params, '=')">
  126. <xsl:call-template name="replaceString">
  127. <xsl:with-param name="string" select="$string"/>
  128. <xsl:with-param name="match" select="substring-before($params, '=')"/>
  129. <xsl:with-param name="replacement" select="substring-after($params, '=')"/>
  130. </xsl:call-template>
  131. </xsl:when>
  132. <xsl:otherwise>
  133. <xsl:value-of select="$string"/>
  134. </xsl:otherwise>
  135. </xsl:choose>
  136. </xsl:template>
  137. <xsl:template name="replaceString">
  138. <xsl:param name="string"/>
  139. <xsl:param name="match"/>
  140. <xsl:param name="replacement"/>
  141. <xsl:choose>
  142. <xsl:when test="contains($string,$match)">
  143. <xsl:value-of select="substring-before($string,$match)"/>
  144. <xsl:value-of select="$replacement"/>
  145. <xsl:call-template name="replaceString">
  146. <xsl:with-param name="string" select="substring-after($string,$match)"/>
  147. <xsl:with-param name="replacement" select="$replacement"/>
  148. <xsl:with-param name="match" select="$match"/>
  149. </xsl:call-template>
  150. </xsl:when>
  151. <xsl:otherwise>
  152. <xsl:value-of select="$string"/>
  153. </xsl:otherwise>
  154. </xsl:choose>
  155. </xsl:template>
  156. </xsl:stylesheet>