delivery_items.xslt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: ps
  5. (C) Copyright IBM Corp. 2005, 2017
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <xsl:stylesheet version="1.0"
  9. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  10. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  11. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  12. xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
  13. xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  14. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  15. exclude-result-prefixes="xsl xsi SOAP-ENC xtsext bus xsd">
  16. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  17. <xsl:key name="env-param" match="/root/*[local-name()='param']" use="@name"/>
  18. <!-- If we're inserting a link into the body -->
  19. <xsl:variable name="insertLink">
  20. <xsl:choose>
  21. <xsl:when test="key('env-param','m_ro_emailAsURL') = 'true' and /root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport'] != ''">true</xsl:when>
  22. <xsl:otherwise>false</xsl:otherwise>
  23. </xsl:choose>
  24. </xsl:variable>
  25. <xsl:variable name="usePowerPlay8Options" select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='usePowerPlay8Options']='true' or key('env-param', 'usePowerPlay8Options')='true'"/>
  26. <xsl:variable name="useJobOptions" select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='useJobOptions']='true' or key('env-param', 'useJobOptions')='true'"/>
  27. <xsl:template match="/root" priority="2">
  28. <xsl:apply-templates/>
  29. <!-- handle the emailAsAttachment and emailAsURL checkboxes -->
  30. <!-- emailAsAttachment -->
  31. <xsl:if test="key('env-param', 'm_ro_emailAsAttachment')">
  32. <xsl:if test="$usePowerPlay8Options or $useJobOptions">
  33. <item xsi:type="bus:powerPlay8OptionBoolean">
  34. <name xsi:type="bus:powerPlay8OptionEnum">emailAsAttachment</name>
  35. <value xsi:type="xsd:boolean">
  36. <xsl:choose>
  37. <xsl:when test="key('env-param','m_ro_emailAsAttachment') = 'true'">true</xsl:when>
  38. <xsl:otherwise>false</xsl:otherwise>
  39. </xsl:choose>
  40. </value>
  41. </item>
  42. </xsl:if>
  43. <xsl:if test="not($usePowerPlay8Options) or $useJobOptions">
  44. <item xsi:type="bus:runOptionBoolean">
  45. <name xsi:type="bus:runOptionEnum">emailAsAttachment</name>
  46. <value xsi:type="xsd:boolean">
  47. <xsl:choose>
  48. <xsl:when test="key('env-param','m_ro_emailAsAttachment') = 'true'">true</xsl:when>
  49. <xsl:otherwise>false</xsl:otherwise>
  50. </xsl:choose>
  51. </value>
  52. </item>
  53. </xsl:if>
  54. </xsl:if>
  55. <!-- emailAsURL -->
  56. <xsl:if test="key('env-param','m_ro_emailAsURL')">
  57. <xsl:if test="$usePowerPlay8Options or $useJobOptions">
  58. <item xsi:type="bus:powerPlay8OptionBoolean">
  59. <name xsi:type="bus:powerPlay8OptionEnum">emailAsURL</name>
  60. <value xsi:type="xsd:boolean">
  61. <xsl:choose>
  62. <!-- only set to true if the checkbox is checked AND we're not called from the report viewer -->
  63. <xsl:when test="key('env-param','m_ro_emailAsURL') = 'true' and not(/root/*[local-name()='requestParams']/*[local-name()='param' and @name='reportViewer']='true')">true</xsl:when>
  64. <xsl:otherwise>false</xsl:otherwise>
  65. </xsl:choose>
  66. </value>
  67. </item>
  68. </xsl:if>
  69. <xsl:if test="not($usePowerPlay8Options) or $useJobOptions">
  70. <item xsi:type="bus:runOptionBoolean">
  71. <name xsi:type="bus:runOptionEnum">emailAsURL</name>
  72. <value xsi:type="xsd:boolean">
  73. <xsl:choose>
  74. <!-- only set to true if the checkbox is checked AND we're not called from the report viewer -->
  75. <xsl:when test="key('env-param','m_ro_emailAsURL') = 'true' and not(/root/*[local-name()='requestParams']/*[local-name()='param' and @name='reportViewer']='true')">true</xsl:when>
  76. <xsl:otherwise>false</xsl:otherwise>
  77. </xsl:choose>
  78. </value>
  79. </item>
  80. </xsl:if>
  81. </xsl:if>
  82. <xsl:variable name="attachmentCount" select="count(/root/*[local-name()='attachments']/*[local-name()='item'])"/>
  83. <!-- did the user select any links. Need this to be a 0 or 1 since it's used in the addition to determine the array size for the memoPart -->
  84. <xsl:variable name="links">
  85. <xsl:choose>
  86. <xsl:when test="count(/root/*[local-name()='links']/*[local-name()='item']) &gt; 0">1</xsl:when>
  87. <xsl:otherwise>0</xsl:otherwise>
  88. </xsl:choose>
  89. </xsl:variable>
  90. <!-- memoPart -->
  91. <xsl:if test="$insertLink = 'true' or key('env-param','email_body')!='' or $attachmentCount &gt; 0 or $links &gt; 0">
  92. <item xsi:type="bus:deliveryOptionMemoPart">
  93. <name xsi:type="bus:deliveryOptionEnum">memoPart</name>
  94. <xsl:choose>
  95. <!-- HTML Body with no attachments -->
  96. <xsl:when test="$links = 0 and $attachmentCount = 0">
  97. <value xsi:type="bus:memoPartComposite">
  98. <xsl:call-template name="htmlBody"/>
  99. </value>
  100. </xsl:when>
  101. <!-- HTML body with attachments -->
  102. <xsl:otherwise>
  103. <xsl:variable name="body">
  104. <xsl:choose>
  105. <xsl:when test="key('env-param','hidden_richEditBody') != '' or key('env-param','email_body')!=''">1</xsl:when>
  106. <xsl:otherwise>0</xsl:otherwise>
  107. </xsl:choose>
  108. </xsl:variable>
  109. <value xsi:type="bus:memoPartComposite">
  110. <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
  111. <contentType xsi:type="bus:smtpContentTypeEnum">mixed</contentType>
  112. <parts xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:memoPart[{$attachmentCount + $links + $body}]">
  113. <xsl:if test="$body = '1' or $links ='0'">
  114. <item xsi:type="bus:memoPartComposite">
  115. <xsl:call-template name="htmlBody"/>
  116. </item>
  117. </xsl:if>
  118. <!-- add the attachments -->
  119. <xsl:call-template name="genAttachmentAndLinkItems"/>
  120. </parts>
  121. </value>
  122. </xsl:otherwise>
  123. </xsl:choose>
  124. </item>
  125. </xsl:if>
  126. </xsl:template>
  127. <!-- generate the item elements for each attachment -->
  128. <xsl:template name="genAttachmentAndLinkItems">
  129. <!-- attachments -->
  130. <xsl:for-each select="/root/*[local-name()='attachments']/*[local-name()='item']">
  131. <item xsi:type="bus:memoPartAgentObject">
  132. <!-- if we have a format and a locale then generate the attachment name -->
  133. <xsl:if test="*[local-name()='format'] != '' and *[local-name()='locale'] != ''">
  134. <xsl:variable name="format" select="*[local-name()='format']"/>
  135. <xsl:variable name="fileExtension">
  136. <xsl:choose>
  137. <xsl:when test="$format='CSV'">.csv</xsl:when>
  138. <xsl:when test="$format='PDF'">.pdf</xsl:when>
  139. <xsl:when test="$format='XML'">.xml</xsl:when>
  140. <xsl:when test="$format='HTML' or $format='XLWA' or $format='MHT'">.mht</xsl:when>
  141. <xsl:when test="$format='spreadsheetML' or $format = 'xlsxData'">.xlsx</xsl:when>
  142. <xsl:when test="$format='XHTML' or $format='HTMLFragment' or $format='XLS' or $format='singleXLS'">.html</xsl:when>
  143. </xsl:choose>
  144. </xsl:variable>
  145. <name xsi:type="xsd:string"><xsl:value-of select="concat(*[local-name()='defaultName'],'_',*[local-name()='locale'],$fileExtension)"/></name>
  146. </xsl:if>
  147. <contentDisposition xsi:type="bus:smtpContentDispositionEnum">attachment</contentDisposition>
  148. <searchPath xsi:type="bus:searchPathSingleObject">
  149. <xsl:value-of select="*[local-name()='searchPath']"/>
  150. </searchPath>
  151. <format xsi:type="xsd:string">
  152. <xsl:value-of select="*[local-name()='format']"/>
  153. </format>
  154. <locale xsi:type="xsd:string">
  155. <xsl:value-of select="*[local-name()='locale']"/>
  156. </locale>
  157. </item>
  158. </xsl:for-each>
  159. <xsl:variable name="links" select="/root/*[local-name()='links']/*[local-name()='item']"/>
  160. <!-- links -->
  161. <xsl:if test="$links">
  162. <item xsi:type="bus:memoPartObjectLinks">
  163. <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
  164. <links xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:objectLink[{count($links)}]">
  165. <xsl:for-each select="$links">
  166. <item xsi:type="bus:objectLink">
  167. <label xsi:type="xsd:string"></label>
  168. <objectClass xsi:type="bus:classEnum">
  169. <xsl:choose>
  170. <xsl:when test="*[local-name()='objectClass'] != ''">
  171. <xsl:value-of select="*[local-name()='objectClass']"/>
  172. </xsl:when>
  173. <xsl:otherwise>
  174. <xsl:text>nil</xsl:text>
  175. </xsl:otherwise>
  176. </xsl:choose>
  177. </objectClass>
  178. <searchPath xsi:type="bus:searchPathSingleObject">
  179. <xsl:value-of select="*[local-name()='searchPath']"/>
  180. </searchPath>
  181. </item>
  182. </xsl:for-each>
  183. </links>
  184. </item>
  185. </xsl:if>
  186. </xsl:template>
  187. <xsl:template name="htmlBody">
  188. <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
  189. <contentType xsi:type="bus:smtpContentTypeEnum">alternative</contentType>
  190. <parts xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:memoPart[2]">
  191. <item xsi:type="bus:memoPartString">
  192. <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
  193. <text xsi:type="xsd:string">
  194. <xsl:value-of select="key('env-param','email_body')"/>
  195. <!-- currently only used for the viewer -->
  196. <xsl:if test="key('env-param','m_ro_emailAsURL')='true' and /root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']!= ''">
  197. <xsl:value-of select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']"/>
  198. </xsl:if>
  199. </text>
  200. </item>
  201. <item xsi:type="bus:memoPartMIMEAttachment">
  202. <xsl:variable name="body">
  203. <xsl:choose>
  204. <xsl:when test="key('env-param','hidden_richEditBody') != ''">
  205. <xsl:value-of select="key('env-param','hidden_richEditBody')"/>
  206. </xsl:when>
  207. <xsl:otherwise>
  208. <xsl:value-of select="key('env-param','email_body')"/>
  209. </xsl:otherwise>
  210. </xsl:choose>
  211. </xsl:variable>
  212. <!-- build up a head and meta element to palce in the HTML email. -->
  213. <xsl:variable name="head">
  214. <xsl:if test="key('env-param','richEditMode') = 'true'">
  215. <xsl:value-of select="'&lt;HEAD&gt;&lt;META name=&quot;user-entered-html-email-body&quot;&gt;&lt;/META&gt;&lt;/HEAD&gt;'"/>
  216. </xsl:if>
  217. </xsl:variable>
  218. <!-- make sure the body has openning and closing BODY and HTML tags -->
  219. <xsl:variable name="htmlBody">
  220. <xsl:choose>
  221. <xsl:when test="starts-with($body,'&lt;HTML')">
  222. <xsl:value-of select="$body"/>
  223. </xsl:when>
  224. <xsl:when test="starts-with($body,'&lt;BODY')">
  225. <xsl:value-of select="concat('&lt;HTML&gt;',$head, $body,'&lt;/HTML&gt;')"/>
  226. </xsl:when>
  227. <xsl:otherwise>
  228. <xsl:value-of select="concat('&lt;HTML&gt;', $head, '&lt;BODY&gt;',$body,'&lt;/BODY&gt;&lt;/HTML&gt;')"/>
  229. </xsl:otherwise>
  230. </xsl:choose>
  231. </xsl:variable>
  232. <!-- if we need to add a link in the body -->
  233. <xsl:variable name="completeBody">
  234. <xsl:choose>
  235. <xsl:when test="key('env-param','m_ro_emailAsURL')='true' and /root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']!= ''">
  236. <xsl:value-of select="substring-before($htmlBody, '&lt;/BODY&gt;&lt;/HTML&gt;')"/>
  237. <xsl:value-of select="'&lt;BR/&gt;'"/>
  238. <xsl:value-of select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']"/>
  239. <xsl:value-of select="'&lt;/BODY&gt;&lt;/HTML&gt;'"/>
  240. </xsl:when>
  241. <xsl:otherwise>
  242. <xsl:value-of select="$htmlBody"/>
  243. </xsl:otherwise>
  244. </xsl:choose>
  245. </xsl:variable>
  246. <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
  247. <name xsi:type="xsd:string"/>
  248. <data xsi:type="xsd:base64Binary"><xsl:value-of select="xtsext:base64encode(string($completeBody), false())"/></data>
  249. <dataSize xsi:type="xsd:integer">0</dataSize>
  250. <dataType xsi:type="xsd:string">text/html</dataType>
  251. </item>
  252. </parts>
  253. </xsl:template>
  254. <!-- typed email to addresses which should have been parsed by process_email_address.xslt transform-->
  255. <xsl:template match="param[@name='to' or @name='cc' or @name='bcc']" priority="1">
  256. <xsl:variable name="typedAddresses" select="concat(@name,'Address')"/>
  257. <xsl:variable name="selectedAddresses" select="@name"/>
  258. <!-- handle the addresses that were typed in -->
  259. <xsl:if test="param[@name=$typedAddresses]">
  260. <item xsi:type="bus:deliveryOptionAddressSMTPArray">
  261. <name xsi:type="bus:deliveryOptionEnum"><xsl:value-of select="$typedAddresses"/></name>
  262. <value xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:addressSMTP[{count(param[@name=$typedAddresses])}]">
  263. <xsl:for-each select="param[@name=$typedAddresses]">
  264. <item xsi:type="bus:addressSMTP">
  265. <xsl:value-of select="."/>
  266. </item>
  267. </xsl:for-each>
  268. </value>
  269. </item>
  270. </xsl:if>
  271. <!-- handle the addresses that were added via the add entries dialog -->
  272. <xsl:if test="param[@name=$selectedAddresses]">
  273. <item xsi:type="bus:deliveryOptionSearchPathMultipleObjectArray">
  274. <name xsi:type="bus:deliveryOptionEnum"><xsl:value-of select="$selectedAddresses"/></name>
  275. <value xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:searchPathMultipleObject[{count(param[@name=$selectedAddresses])}]">
  276. <xsl:for-each select="param[@name=$selectedAddresses]">
  277. <item xsi:type="bus:searchPathMultipleObject">
  278. <xsl:value-of select="."/>
  279. </item>
  280. </xsl:for-each>
  281. </value>
  282. </item>
  283. </xsl:if>
  284. </xsl:template>
  285. <!-- email subject -->
  286. <xsl:template match="param[@name='email_subject']" priority="1">
  287. <item xsi:type="bus:deliveryOptionString">
  288. <name xsi:type="bus:deliveryOptionEnum">subject</name>
  289. <value xsi:type="xsd:string"><xsl:value-of select="."/></value>
  290. </item>
  291. </xsl:template>
  292. <xsl:template match="text()" priority="0"/>
  293. </xsl:stylesheet>