123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Licensed Materials - Property of IBM
- IBM Cognos Products: ps
- (C) Copyright IBM Corp. 2005, 2017
- US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- -->
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:bus="http://developer.cognos.com/schemas/bibus/3/"
- xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
- xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
- exclude-result-prefixes="xsl xsi SOAP-ENC xtsext bus xsd">
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
-
- <xsl:key name="env-param" match="/root/*[local-name()='param']" use="@name"/>
- <!-- If we're inserting a link into the body -->
- <xsl:variable name="insertLink">
- <xsl:choose>
- <xsl:when test="key('env-param','m_ro_emailAsURL') = 'true' and /root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport'] != ''">true</xsl:when>
- <xsl:otherwise>false</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="usePowerPlay8Options" select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='usePowerPlay8Options']='true' or key('env-param', 'usePowerPlay8Options')='true'"/>
- <xsl:variable name="useJobOptions" select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='useJobOptions']='true' or key('env-param', 'useJobOptions')='true'"/>
- <xsl:template match="/root" priority="2">
- <xsl:apply-templates/>
- <!-- handle the emailAsAttachment and emailAsURL checkboxes -->
- <!-- emailAsAttachment -->
- <xsl:if test="key('env-param', 'm_ro_emailAsAttachment')">
- <xsl:if test="$usePowerPlay8Options or $useJobOptions">
- <item xsi:type="bus:powerPlay8OptionBoolean">
- <name xsi:type="bus:powerPlay8OptionEnum">emailAsAttachment</name>
- <value xsi:type="xsd:boolean">
- <xsl:choose>
- <xsl:when test="key('env-param','m_ro_emailAsAttachment') = 'true'">true</xsl:when>
- <xsl:otherwise>false</xsl:otherwise>
- </xsl:choose>
- </value>
- </item>
- </xsl:if>
- <xsl:if test="not($usePowerPlay8Options) or $useJobOptions">
- <item xsi:type="bus:runOptionBoolean">
- <name xsi:type="bus:runOptionEnum">emailAsAttachment</name>
- <value xsi:type="xsd:boolean">
- <xsl:choose>
- <xsl:when test="key('env-param','m_ro_emailAsAttachment') = 'true'">true</xsl:when>
- <xsl:otherwise>false</xsl:otherwise>
- </xsl:choose>
- </value>
- </item>
- </xsl:if>
- </xsl:if>
- <!-- emailAsURL -->
- <xsl:if test="key('env-param','m_ro_emailAsURL')">
- <xsl:if test="$usePowerPlay8Options or $useJobOptions">
- <item xsi:type="bus:powerPlay8OptionBoolean">
- <name xsi:type="bus:powerPlay8OptionEnum">emailAsURL</name>
- <value xsi:type="xsd:boolean">
- <xsl:choose>
- <!-- only set to true if the checkbox is checked AND we're not called from the report viewer -->
- <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>
- <xsl:otherwise>false</xsl:otherwise>
- </xsl:choose>
- </value>
- </item>
- </xsl:if>
- <xsl:if test="not($usePowerPlay8Options) or $useJobOptions">
- <item xsi:type="bus:runOptionBoolean">
- <name xsi:type="bus:runOptionEnum">emailAsURL</name>
- <value xsi:type="xsd:boolean">
- <xsl:choose>
- <!-- only set to true if the checkbox is checked AND we're not called from the report viewer -->
- <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>
- <xsl:otherwise>false</xsl:otherwise>
- </xsl:choose>
- </value>
- </item>
- </xsl:if>
- </xsl:if>
- <xsl:variable name="attachmentCount" select="count(/root/*[local-name()='attachments']/*[local-name()='item'])"/>
- <!-- 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 -->
- <xsl:variable name="links">
- <xsl:choose>
- <xsl:when test="count(/root/*[local-name()='links']/*[local-name()='item']) > 0">1</xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
-
- <!-- memoPart -->
- <xsl:if test="$insertLink = 'true' or key('env-param','email_body')!='' or $attachmentCount > 0 or $links > 0">
- <item xsi:type="bus:deliveryOptionMemoPart">
- <name xsi:type="bus:deliveryOptionEnum">memoPart</name>
- <xsl:choose>
- <!-- HTML Body with no attachments -->
- <xsl:when test="$links = 0 and $attachmentCount = 0">
- <value xsi:type="bus:memoPartComposite">
- <xsl:call-template name="htmlBody"/>
- </value>
- </xsl:when>
- <!-- HTML body with attachments -->
- <xsl:otherwise>
- <xsl:variable name="body">
- <xsl:choose>
- <xsl:when test="key('env-param','hidden_richEditBody') != '' or key('env-param','email_body')!=''">1</xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <value xsi:type="bus:memoPartComposite">
- <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
- <contentType xsi:type="bus:smtpContentTypeEnum">mixed</contentType>
- <parts xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:memoPart[{$attachmentCount + $links + $body}]">
- <xsl:if test="$body = '1' or $links ='0'">
- <item xsi:type="bus:memoPartComposite">
- <xsl:call-template name="htmlBody"/>
- </item>
- </xsl:if>
- <!-- add the attachments -->
- <xsl:call-template name="genAttachmentAndLinkItems"/>
- </parts>
- </value>
- </xsl:otherwise>
- </xsl:choose>
- </item>
- </xsl:if>
- </xsl:template>
-
- <!-- generate the item elements for each attachment -->
- <xsl:template name="genAttachmentAndLinkItems">
- <!-- attachments -->
- <xsl:for-each select="/root/*[local-name()='attachments']/*[local-name()='item']">
- <item xsi:type="bus:memoPartAgentObject">
- <!-- if we have a format and a locale then generate the attachment name -->
- <xsl:if test="*[local-name()='format'] != '' and *[local-name()='locale'] != ''">
- <xsl:variable name="format" select="*[local-name()='format']"/>
- <xsl:variable name="fileExtension">
- <xsl:choose>
- <xsl:when test="$format='CSV'">.csv</xsl:when>
- <xsl:when test="$format='PDF'">.pdf</xsl:when>
- <xsl:when test="$format='XML'">.xml</xsl:when>
- <xsl:when test="$format='HTML' or $format='XLWA' or $format='MHT'">.mht</xsl:when>
- <xsl:when test="$format='spreadsheetML' or $format = 'xlsxData'">.xlsx</xsl:when>
- <xsl:when test="$format='XHTML' or $format='HTMLFragment' or $format='XLS' or $format='singleXLS'">.html</xsl:when>
- </xsl:choose>
- </xsl:variable>
- <name xsi:type="xsd:string"><xsl:value-of select="concat(*[local-name()='defaultName'],'_',*[local-name()='locale'],$fileExtension)"/></name>
- </xsl:if>
- <contentDisposition xsi:type="bus:smtpContentDispositionEnum">attachment</contentDisposition>
- <searchPath xsi:type="bus:searchPathSingleObject">
- <xsl:value-of select="*[local-name()='searchPath']"/>
- </searchPath>
- <format xsi:type="xsd:string">
- <xsl:value-of select="*[local-name()='format']"/>
- </format>
- <locale xsi:type="xsd:string">
- <xsl:value-of select="*[local-name()='locale']"/>
- </locale>
- </item>
- </xsl:for-each>
-
- <xsl:variable name="links" select="/root/*[local-name()='links']/*[local-name()='item']"/>
- <!-- links -->
- <xsl:if test="$links">
- <item xsi:type="bus:memoPartObjectLinks">
- <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
- <links xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:objectLink[{count($links)}]">
- <xsl:for-each select="$links">
- <item xsi:type="bus:objectLink">
- <label xsi:type="xsd:string"></label>
- <objectClass xsi:type="bus:classEnum">
- <xsl:choose>
- <xsl:when test="*[local-name()='objectClass'] != ''">
- <xsl:value-of select="*[local-name()='objectClass']"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>nil</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </objectClass>
- <searchPath xsi:type="bus:searchPathSingleObject">
- <xsl:value-of select="*[local-name()='searchPath']"/>
- </searchPath>
- </item>
- </xsl:for-each>
- </links>
- </item>
- </xsl:if>
- </xsl:template>
-
- <xsl:template name="htmlBody">
- <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
- <contentType xsi:type="bus:smtpContentTypeEnum">alternative</contentType>
- <parts xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:memoPart[2]">
- <item xsi:type="bus:memoPartString">
- <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
- <text xsi:type="xsd:string">
- <xsl:value-of select="key('env-param','email_body')"/>
-
- <!-- currently only used for the viewer -->
- <xsl:if test="key('env-param','m_ro_emailAsURL')='true' and /root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']!= ''">
- <xsl:value-of select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']"/>
- </xsl:if>
- </text>
- </item>
- <item xsi:type="bus:memoPartMIMEAttachment">
- <xsl:variable name="body">
- <xsl:choose>
- <xsl:when test="key('env-param','hidden_richEditBody') != ''">
- <xsl:value-of select="key('env-param','hidden_richEditBody')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="key('env-param','email_body')"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <!-- build up a head and meta element to palce in the HTML email. -->
- <xsl:variable name="head">
- <xsl:if test="key('env-param','richEditMode') = 'true'">
- <xsl:value-of select="'<HEAD><META name="user-entered-html-email-body"></META></HEAD>'"/>
- </xsl:if>
- </xsl:variable>
- <!-- make sure the body has openning and closing BODY and HTML tags -->
- <xsl:variable name="htmlBody">
- <xsl:choose>
- <xsl:when test="starts-with($body,'<HTML')">
- <xsl:value-of select="$body"/>
- </xsl:when>
- <xsl:when test="starts-with($body,'<BODY')">
- <xsl:value-of select="concat('<HTML>',$head, $body,'</HTML>')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="concat('<HTML>', $head, '<BODY>',$body,'</BODY></HTML>')"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <!-- if we need to add a link in the body -->
- <xsl:variable name="completeBody">
- <xsl:choose>
- <xsl:when test="key('env-param','m_ro_emailAsURL')='true' and /root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']!= ''">
- <xsl:value-of select="substring-before($htmlBody, '</BODY></HTML>')"/>
- <xsl:value-of select="'<BR/>'"/>
- <xsl:value-of select="/root/*[local-name()='requestParams']/*[local-name()='param' and @name='linkToReport']"/>
- <xsl:value-of select="'</BODY></HTML>'"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$htmlBody"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <contentDisposition xsi:type="bus:smtpContentDispositionEnum">inline</contentDisposition>
- <name xsi:type="xsd:string"/>
- <data xsi:type="xsd:base64Binary"><xsl:value-of select="xtsext:base64encode(string($completeBody), false())"/></data>
- <dataSize xsi:type="xsd:integer">0</dataSize>
- <dataType xsi:type="xsd:string">text/html</dataType>
- </item>
- </parts>
- </xsl:template>
-
- <!-- typed email to addresses which should have been parsed by process_email_address.xslt transform-->
- <xsl:template match="param[@name='to' or @name='cc' or @name='bcc']" priority="1">
- <xsl:variable name="typedAddresses" select="concat(@name,'Address')"/>
- <xsl:variable name="selectedAddresses" select="@name"/>
- <!-- handle the addresses that were typed in -->
- <xsl:if test="param[@name=$typedAddresses]">
- <item xsi:type="bus:deliveryOptionAddressSMTPArray">
- <name xsi:type="bus:deliveryOptionEnum"><xsl:value-of select="$typedAddresses"/></name>
- <value xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:addressSMTP[{count(param[@name=$typedAddresses])}]">
- <xsl:for-each select="param[@name=$typedAddresses]">
- <item xsi:type="bus:addressSMTP">
- <xsl:value-of select="."/>
- </item>
- </xsl:for-each>
- </value>
- </item>
- </xsl:if>
- <!-- handle the addresses that were added via the add entries dialog -->
- <xsl:if test="param[@name=$selectedAddresses]">
- <item xsi:type="bus:deliveryOptionSearchPathMultipleObjectArray">
- <name xsi:type="bus:deliveryOptionEnum"><xsl:value-of select="$selectedAddresses"/></name>
- <value xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:searchPathMultipleObject[{count(param[@name=$selectedAddresses])}]">
- <xsl:for-each select="param[@name=$selectedAddresses]">
- <item xsi:type="bus:searchPathMultipleObject">
- <xsl:value-of select="."/>
- </item>
- </xsl:for-each>
- </value>
- </item>
- </xsl:if>
- </xsl:template>
-
- <!-- email subject -->
- <xsl:template match="param[@name='email_subject']" priority="1">
- <item xsi:type="bus:deliveryOptionString">
- <name xsi:type="bus:deliveryOptionEnum">subject</name>
- <value xsi:type="xsd:string"><xsl:value-of select="."/></value>
- </item>
- </xsl:template>
-
- <xsl:template match="text()" priority="0"/>
- </xsl:stylesheet>
|