process_email_address.xslt 6.5 KB

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