synchronize.xslt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  15. xmlns:xts="http://developer.cognos.com/schemas/xts/">
  16. <xsl:output method="xml" encoding="UTF-8" version="1.0" indent="no"/>
  17. <xsl:template match="/root">
  18. <!-- The list of portlets defined for the page -->
  19. <xsl:variable name="portletItems">
  20. <xsl:for-each select="env/param[starts-with(@name, 'm_mp_portlet_')]">
  21. <xsl:if test=". != ''">
  22. <xsl:value-of select="concat(' ', substring-after(@name, 'm_mp_portlet_'), ' ')"/>
  23. </xsl:if>
  24. </xsl:for-each>
  25. </xsl:variable>
  26. <!-- The list of portlets that exist in the current layout -->
  27. <xsl:variable name="placedPortletItems">
  28. <xsl:for-each select="/root/layout/column/portlet">
  29. <xsl:value-of select="concat(' ', @id, ' ')"/>
  30. </xsl:for-each>
  31. </xsl:variable>
  32. <xts:sequence>
  33. <!-- Remove portlet references in the layout object that no longer exist in the portlet items list -->
  34. <xts:delete select="/root/layout/column/portlet[not(contains('{$portletItems}', @id))]"/>
  35. <!-- Add references to portletInstances that are not already represented in the layout -->
  36. <xsl:for-each select="/root/env/param[starts-with(@name, 'm_mp_portlet_')]">
  37. <xsl:if test="not(contains($placedPortletItems, substring-after(@name, 'm_mp_portlet_')))">
  38. <xsl:choose>
  39. <xsl:when test="/root/env/param[@name='m_mp_cmd'] = 'add_portlet_2'">
  40. <xts:append select="/root/layout/column[2]">
  41. <portlet id="{substring-after(@name, 'm_mp_portlet_')}"/>
  42. </xts:append>
  43. </xsl:when>
  44. <xsl:when test="/root/env/param[@name='m_mp_cmd'] = 'add_portlet_3'">
  45. <xts:append select="/root/layout/column[3]">
  46. <portlet id="{substring-after(@name, 'm_mp_portlet_')}"/>
  47. </xts:append>
  48. </xsl:when>
  49. <xsl:otherwise>
  50. <xts:append select="/root/layout/column[1]">
  51. <portlet id="{substring-after(@name, 'm_mp_portlet_')}"/>
  52. </xts:append>
  53. </xsl:otherwise>
  54. </xsl:choose>
  55. </xsl:if>
  56. </xsl:for-each>
  57. </xts:sequence>
  58. </xsl:template>
  59. </xsl:stylesheet>