performAction.xslt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. xmlns:cm="http://developer.cognos.com/schemas/xts-cm/1/"
  15. exclude-result-prefixes="xsl cm">
  16. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  17. <xsl:key name="env-param" match="/content/env/param" use="@name"/>
  18. <xsl:key name="nav-param" match="/content/env/param[starts-with(@name,'nav_checkbox')]" use="."/>
  19. <xsl:key name="list-param" match="/content/env/param[starts-with(@name,'list_checkbox')]" use="."/>
  20. <xsl:key name="type-entries" match="/content/entry/results/cm:queryResponse/*/*[local-name()='searchPath']" use="."/>
  21. <xsl:template match="/content" priority="1">
  22. <content>
  23. <cm:queryResponse>
  24. <xsl:copy-of select="cm:queryResponse/cm:queryReply[position()='1' or position()='2']"/>
  25. </cm:queryResponse>
  26. </content>
  27. <xsl:if test="starts-with(/content/action, 'add')">
  28. <xsl:apply-templates select="." mode="add"/>
  29. </xsl:if>
  30. <xsl:if test="starts-with(/content/action, 'remove')">
  31. <xsl:apply-templates select="." mode="remove"/>
  32. </xsl:if>
  33. </xsl:template>
  34. <!-- user hit the remove button -->
  35. <xsl:template match="*" mode="remove">
  36. <selectedEntries>
  37. <xsl:for-each select="/content/*[local-name()='selectedEntries']/*">
  38. <!-- make the position 0 based since we used preceding-sibling for the
  39. checkbox value which is 0 based -->
  40. <xsl:variable name="pos" select="position()-1"/>
  41. <xsl:if test="not(key('list-param',$pos))">
  42. <xsl:copy-of select="."/>
  43. </xsl:if>
  44. </xsl:for-each>
  45. </selectedEntries>
  46. </xsl:template>
  47. <!-- user hit the add button -->
  48. <xsl:template match="*" mode="add">
  49. <!-- flag duplicate entries if allowDuplicated is set to false -->
  50. <xsl:choose>
  51. <xsl:when test="/content/dialog != 'type' and /content/allowDuplicates = 'false' and key('nav-param', /content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath'])">
  52. <duplicateEntry>true</duplicateEntry>
  53. </xsl:when>
  54. <xsl:when test="/content/dialog = 'type' and /content/allowDuplicates = 'false' and key('type-entries', /content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath'])">
  55. <duplicateEntry>true</duplicateEntry>
  56. </xsl:when>
  57. </xsl:choose>
  58. <xsl:if test="/content/dialog = 'type'">
  59. <invalid_typed_entries>
  60. <xsl:for-each select="/content/entry[not(results/cm:queryResponse/*)]">
  61. <xsl:value-of select="namespace-name"/>
  62. <xsl:if test="object-name!=''">
  63. <xsl:value-of select="concat('/',object-name)"/>
  64. </xsl:if>
  65. <xsl:text>; </xsl:text>
  66. </xsl:for-each>
  67. </invalid_typed_entries>
  68. </xsl:if>
  69. <selectedEntries>
  70. <!-- copy over the entries that were already added -->
  71. <xsl:copy-of select="./*[local-name()='selectedEntries']/*"/>
  72. <xsl:choose>
  73. <!-- adding entries from the type tab -->
  74. <xsl:when test="/content/dialog = 'type'">
  75. <xsl:for-each select="/content/entry/results/cm:queryResponse/*/*[local-name()='searchPath']">
  76. <xsl:variable name="searchPath" select="."/>
  77. <!-- don't add duplicated if allowDuplicate is false -->
  78. <xsl:if test="/content/allowDuplicates = 'true' or not(/content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath' and string(.) = $searchPath])">
  79. <xsl:apply-templates select="/content/entry/results/cm:queryResponse/*[*[local-name()='searchPath' and string(.) = $searchPath]]" mode="addItem"/>
  80. </xsl:if>
  81. </xsl:for-each>
  82. </xsl:when>
  83. <xsl:otherwise>
  84. <xsl:for-each select="/content/env/param[@name = 'nav_checkbox']">
  85. <xsl:variable name="searchPath" select="."/>
  86. <xsl:choose>
  87. <!-- don't add duplicate entries if allowDuplicated is set to false -->
  88. <xsl:when test="/content/allowDuplicates = 'false' and /content/*[local-name()='selectedEntries']/*/*[local-name()='searchPath' and string(.) = $searchPath]"/>
  89. <xsl:when test="/content/cm:queryResponse/cm:queryReply[position() &gt;= number(/content/addedQueryPosition)]/*/*[local-name()='searchPath' and string(.) = $searchPath]">
  90. <xsl:apply-templates select="/content/cm:queryResponse/cm:queryReply[position() &gt;= number(/content/addedQueryPosition)]/*[*[local-name()='searchPath' and string(.) = $searchPath]]" mode="addItem"/>
  91. </xsl:when>
  92. </xsl:choose>
  93. </xsl:for-each>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </selectedEntries>
  97. </xsl:template>
  98. <xsl:template match="*" mode="addItem">
  99. <!-- find out if the user hit the add 'To', 'Cc', 'Bcc' or the standard add button -->
  100. <xsl:variable name="type" select="substring-after(/content/action, 'add_')"/>
  101. <xsl:element name="{local-name()}" namespace="http://developer.cognos.com/schemas/xts-cm/1/">
  102. <xsl:if test="$type != ''">
  103. <type><xsl:value-of select="$type"/></type>
  104. </xsl:if>
  105. <xsl:apply-templates mode="addProperties"/>
  106. </xsl:element>
  107. </xsl:template>
  108. <xsl:template match="*" mode="addProperties">
  109. <xsl:variable name="propertyName" select="local-name()"/>
  110. <xsl:if test="$propertyName = 'searchPath' or $propertyName = 'objectClass' or $propertyName = 'defaultName' or $propertyName = 'base' or $propertyName='searchPathForURL' or $propertyName='hidden' or /content/*[local-name()='property' and @name=$propertyName]">
  111. <xsl:copy-of select="."/>
  112. </xsl:if>
  113. <xsl:if test="$propertyName = 'ancestors'">
  114. <xsl:element name="{local-name()}" namespace="http://developer.cognos.com/schemas/xts-cm/1/">
  115. <xsl:copy-of select="./*"/>
  116. </xsl:element>
  117. </xsl:if>
  118. </xsl:template>
  119. <xsl:template match="text()" priority="0"/>
  120. </xsl:stylesheet>