process_email_address.xslt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, 2011
  6. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. -->
  8. <!--
  9. Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  10. Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  11. -->
  12. <xsl:stylesheet version="1.0"
  13. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  14. exclude-result-prefixes="xsl">
  15. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  16. <xsl:key name="env-param" match="/root/env/param" use="@name"/>
  17. <xsl:template match="/root/env" priority="3">
  18. <xsl:apply-templates/>
  19. </xsl:template>
  20. <!-- handle the email to field -->
  21. <xsl:template match="param[@name='email_to']" priority="2">
  22. <param name="to">
  23. <xsl:call-template name="parse-addresses">
  24. <xsl:with-param name="addresses" select="."/>
  25. <xsl:with-param name="propertyType" select="'to'"/>
  26. </xsl:call-template>
  27. </param>
  28. </xsl:template>
  29. <!-- handle the email cc field -->
  30. <xsl:template match="param[@name='email_cc']" priority="2">
  31. <param name="cc">
  32. <xsl:call-template name="parse-addresses">
  33. <xsl:with-param name="addresses" select="."/>
  34. <xsl:with-param name="propertyType" select="'cc'"/>
  35. </xsl:call-template>
  36. </param>
  37. </xsl:template>
  38. <!-- handle the email bcc field -->
  39. <xsl:template match="param[@name='email_bcc']" priority="2">
  40. <param name="bcc">
  41. <xsl:call-template name="parse-addresses">
  42. <xsl:with-param name="addresses" select="."/>
  43. <xsl:with-param name="propertyType" select="'bcc'"/>
  44. </xsl:call-template>
  45. </param>
  46. </xsl:template>
  47. <!-- recursively trim the trailing spaces from a string -->
  48. <xsl:template name="trimTrailingSpaces">
  49. <xsl:param name="strInput" select="''" />
  50. <xsl:variable name="strLen" select="string-length($strInput)" />
  51. <xsl:variable name="strOutput" select="substring($strInput, 1, $strLen - 1 )" />
  52. <xsl:variable name="strLastChar" select="substring($strInput, $strLen, 1 )" />
  53. <xsl:choose>
  54. <xsl:when test="$strLastChar = ' '">
  55. <!-- call the template recursively until it is trimmed -->
  56. <xsl:call-template name="trimTrailingSpaces">
  57. <xsl:with-param name="strInput" select="$strOutput" />
  58. </xsl:call-template>
  59. </xsl:when>
  60. <xsl:otherwise>
  61. <xsl:value-of select="$strInput" />
  62. </xsl:otherwise>
  63. </xsl:choose>
  64. </xsl:template>
  65. <!-- recursively trim the leading spaces from a string -->
  66. <xsl:template name="trimLeadingSpaces">
  67. <xsl:param name="strInput" select="''" />
  68. <xsl:variable name="strLen" select="string-length($strInput)" />
  69. <xsl:variable name="strOutput" select="substring($strInput, 2, $strLen - 1 )" />
  70. <xsl:variable name="strFirstChar" select="substring($strInput, 1, 1 )" />
  71. <xsl:choose>
  72. <xsl:when test="$strFirstChar = ' '">
  73. <!-- call the template recursively until it is trimmed -->
  74. <xsl:call-template name="trimLeadingSpaces">
  75. <xsl:with-param name="strInput" select="$strOutput" />
  76. </xsl:call-template>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <xsl:value-of select="$strInput" />
  80. </xsl:otherwise>
  81. </xsl:choose>
  82. </xsl:template>
  83. <!-- recursively trim the trailing and leading spaces from a string (calls templates trimLeadingSpaces and trimTrailingSpaces) -->
  84. <xsl:template name="trimTrailingLeadingSpaces">
  85. <xsl:param name="strInput" select="''" />
  86. <!-- trim off leading spaces (recursively) -->
  87. <xsl:variable name="strTrimmed1">
  88. <xsl:call-template name="trimLeadingSpaces">
  89. <xsl:with-param name="strInput" select="$strInput" />
  90. </xsl:call-template>
  91. </xsl:variable>
  92. <!-- trim off trailing spaces (recursively) -->
  93. <xsl:variable name="strTrimmed2">
  94. <xsl:call-template name="trimTrailingSpaces">
  95. <xsl:with-param name="strInput" select="$strTrimmed1" />
  96. </xsl:call-template>
  97. </xsl:variable>
  98. <xsl:value-of select="$strTrimmed2" />
  99. </xsl:template>
  100. <xsl:template name="parse-addresses">
  101. <xsl:param name="addresses" select="''"/>
  102. <xsl:param name="propertyType"/>
  103. <xsl:if test="$addresses != ''">
  104. <xsl:variable name="before">
  105. <xsl:choose>
  106. <xsl:when test="contains($addresses,';')">
  107. <!-- Trim leading and trailing spaces -->
  108. <xsl:call-template name="trimTrailingLeadingSpaces">
  109. <xsl:with-param name="strInput" select="substring-before($addresses,';')" />
  110. </xsl:call-template>
  111. </xsl:when>
  112. <xsl:otherwise>
  113. <xsl:call-template name="trimTrailingLeadingSpaces">
  114. <xsl:with-param name="strInput" select="$addresses" />
  115. </xsl:call-template>
  116. </xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:variable>
  119. <xsl:variable name="after">
  120. <xsl:if test="contains($addresses,';')">
  121. <!-- Trim leading and trailing spaces -->
  122. <xsl:call-template name="trimTrailingLeadingSpaces">
  123. <xsl:with-param name="strInput" select="substring-after($addresses,';')" />
  124. </xsl:call-template>
  125. </xsl:if>
  126. </xsl:variable>
  127. <xsl:if test="$before!=''">
  128. <!-- this is where we check to see if the address was types in or selected from the add entries dialog -->
  129. <xsl:choose>
  130. <xsl:when test="/root/*[local-name()='addedRecipients']/*[*[local-name()='displayName' and string(.) = $before]]/*[local-name()='type' and string(.)=$propertyType]">
  131. <param name="{$propertyType}"><xsl:value-of select="/root/*[local-name()='addedRecipients']/*[*[local-name()='displayName' and string(.) = $before]]/*[local-name()='searchPath']"/></param>
  132. </xsl:when>
  133. <xsl:otherwise>
  134. <param name="{concat($propertyType,'Address')}"><xsl:value-of select="$before"/></param>
  135. </xsl:otherwise>
  136. </xsl:choose>
  137. </xsl:if>
  138. <xsl:if test="$after!=''">
  139. <xsl:call-template name="parse-addresses">
  140. <xsl:with-param name="addresses" select="$after"/>
  141. <xsl:with-param name="propertyType" select="$propertyType"/>
  142. </xsl:call-template>
  143. </xsl:if>
  144. </xsl:if>
  145. </xsl:template>
  146. <!-- copy all other params -->
  147. <xsl:template match="*[local-name()='param']" priority="1">
  148. <xsl:element name="param">
  149. <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
  150. <xsl:value-of select="."/>
  151. </xsl:element>
  152. </xsl:template>
  153. <xsl:template match="text()" priority="0"/>
  154. </xsl:stylesheet>