mergeTenantNames.xslt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. 2013
  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:xts="http://developer.cognos.com/schemas/xts/"
  10. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  11. xmlns:set="http://exslt.org/sets"
  12. xmlns:send="http://developer.cognos.com/schemas/xts/logic-sheet/xslt/brl/1/"
  13. xmlns:xtsext="xalan://com.cognos.xts.ext.XTSExt"
  14. exclude-result-prefixes="xts send set xtsext">
  15. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
  16. <xsl:template match="/">
  17. <xsl:variable name="distinctTenantIds" select="set:distinct(/root//*[local-name()='queryResponse' or local-name()='response']//*[local-name()='tenantID' and text()!=''] | /root//*[local-name() = 'Property' and @name='TenantID'])"/>
  18. <xts:sequence>
  19. <xts:append>
  20. <xsl:variable name="tenantSearchPath">
  21. <xsl:text>/directory/tenants[@name='Tenants']/tenant</xsl:text>
  22. <xsl:for-each select="$distinctTenantIds">
  23. <xsl:variable name="sq">'</xsl:variable>
  24. <!-- must escape the ' to '' to make the search expression CM safe. -->
  25. <xsl:variable name="cmEncodedObjTenantId" select="xtsext:replace(string(.), string($sq), concat($sq,$sq)) "/>
  26. <xsl:if test="position()=1">
  27. <xsl:text>[</xsl:text>
  28. </xsl:if>
  29. <xsl:text>@tenantID='</xsl:text><xsl:value-of select="$cmEncodedObjTenantId"/><xsl:text>'</xsl:text>
  30. <xsl:if test="not(position()=last())">
  31. <xsl:text> or </xsl:text>
  32. </xsl:if>
  33. <xsl:if test="position()=last()">
  34. <xsl:text>]</xsl:text>
  35. </xsl:if>
  36. </xsl:for-each>
  37. </xsl:variable>
  38. <tenantIDs>
  39. <xts:transform src="transforms/CM/post-process.xslt" processor="XSLT">
  40. <send:request provider="cm">
  41. <xts:transform src="transforms/CM/pre-process.xslt" processor="XSLT">
  42. <cm:query xmlns:cm="http://developer.cognos.com/schemas/xts-cm/1/">
  43. <cm:search><xsl:value-of select="normalize-space($tenantSearchPath)"/></cm:search>
  44. <cm:properties>
  45. <cm:property name="defaultName"/>
  46. <cm:property name="tenantID"/>
  47. </cm:properties>
  48. <cm:options schemaInfo="false"/>
  49. </cm:query>
  50. </xts:transform>
  51. </send:request>
  52. </xts:transform>
  53. </tenantIDs>
  54. </xts:append>
  55. </xts:sequence>
  56. <xsl:for-each select="$distinctTenantIds">
  57. <xsl:variable name="tenantID" select="."/>
  58. <xts:sequence>
  59. <xts:update>
  60. <xsl:attribute name="select">
  61. <xsl:text>/root//*[local-name()='queryResponse' or local-name()='response']//*[local-name()='tenantID' and text()='</xsl:text><xsl:value-of select="$tenantID"/><xsl:text>'] | /root//*[local-name() = 'Property' and @name='TenantID' and text()='</xsl:text><xsl:value-of select="$tenantID"/><xsl:text>']</xsl:text>
  62. </xsl:attribute>
  63. <tenantID xmlns="http://developer.cognos.com/schemas/xts-cm/1/"><xsl:value-of select="$tenantID"/></tenantID>
  64. <tenantName xmlns="http://developer.cognos.com/schemas/xts-cm/1/">
  65. <xts:queryNode>
  66. <xsl:attribute name="select">
  67. <xsl:text>/root/*[local-name()='tenantIDs']//*[local-name()='tenantID' and text()='</xsl:text><xsl:value-of select="$tenantID"/><xsl:text>']/../*[local-name()='defaultName']</xsl:text>
  68. </xsl:attribute>
  69. </xts:queryNode>
  70. </tenantName>
  71. </xts:update>
  72. </xts:sequence>
  73. </xsl:for-each>
  74. </xsl:template>
  75. </xsl:stylesheet>