output-message.xsl 6.3 KB

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