asvResultset.xslt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. <!--
  9. Agent Service version 1.0
  10. NB this stylesheet is run on a DOM I complient parser by rsvp
  11. there is only minimal namespace handling
  12. NB that means that if there is an attribute with a namespace like bus:name you have to test it with name() = 'bus:name' no other test will work
  13. -->
  14. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rsext="xalan://com.cognos.reportserver.ext.RSExt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:bus="http://developer.cognos.com/schemas/bibus/3/">
  15. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  16. <xsl:template match="/">
  17. <!-- Check for a table header -->
  18. <dataset version="1.0">
  19. <xsl:element name="metadata">
  20. <xsl:apply-templates select="//DR[./DRI[@type='columnTitle']]" mode="metadata"/>
  21. </xsl:element>
  22. <xsl:element name="data">
  23. <xsl:apply-templates select="//DR[./DRI[@type='datavalue']]" mode="data"/>
  24. </xsl:element>
  25. <xsl:element name="drills">
  26. <xsl:apply-templates select="//DRILLS"/>
  27. </xsl:element>
  28. </dataset>
  29. </xsl:template>
  30. <xsl:template match="DR" mode="metadata">
  31. <xsl:for-each select="DRI">
  32. <xsl:variable name="position" select="position()"/>
  33. <xsl:element name="item">
  34. <xsl:attribute name="name"><xsl:value-of select="//DR/DRI[@type='columnTitle'][position()=$position]/OTI"/></xsl:attribute>
  35. <xsl:variable name="drillIndex">
  36. <xsl:value-of select="number(//DR[./DRI[@type='datavalue']][last()]/DRI[position()=$position]//drillTargets/drillTarget/@drillIdx) + 1"/>
  37. </xsl:variable>
  38. <xsl:attribute name="type">
  39. <!-- the xsd type is a new feature for raw xml in late bering mr2 -->
  40. <xsl:choose>
  41. <xsl:when test="//DR[./DRI[@type='datavalue']]/DRI[position()=$position]/OTI/@xsdType">
  42. <xsl:value-of select="//DR[./DRI[@type='datavalue']]/DRI[position()=$position]/OTI/@xsdType"/>
  43. </xsl:when>
  44. <xsl:when test="//DR[./DRI[@type='datavalue']]/DRI[position()=$position]//OIMG">
  45. <xsl:text>xsdString</xsl:text>
  46. </xsl:when>
  47. <xsl:when test="./OTI/@xsdType">
  48. <xsl:value-of select="./OTI/@xsdType"/>
  49. </xsl:when>
  50. <xsl:otherwise>
  51. <xsl:value-of select="./OTI/@valueType"/>
  52. </xsl:otherwise>
  53. </xsl:choose>
  54. </xsl:attribute>
  55. <xsl:variable name="drillType">
  56. <xsl:value-of select="//DRILLS/DRILL[position()=$drillIndex]/*[name()='bus:parameters']/item/*[name()='bus:type']"/>
  57. </xsl:variable>
  58. <!--will we have a mun value available ? welcome to the crazy world of raw xml -->
  59. <xsl:attribute name="mun">
  60. <xsl:choose>
  61. <xsl:when test="//DR[./DRI[@type='datavalue']]/DRI[position()=$position]//drillTargets/drillTarget/drillParameter/@mun != ''">true</xsl:when>
  62. <xsl:when test="$drillType='memberUniqueName' and //DR[./DRI[@type='datavalue']]/DRI[position()=$position]//drillTargets/drillTarget/drillParameter/@value != ''">true</xsl:when>
  63. <xsl:otherwise>false</xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:attribute>
  66. </xsl:element>
  67. </xsl:for-each>
  68. </xsl:template>
  69. <xsl:template match="DR" mode="data">
  70. <xsl:element name="row">
  71. <xsl:apply-templates select="./DRI[@type='datavalue']//*[local-name()='OTI' or local-name()='OIMG']"/>
  72. </xsl:element>
  73. </xsl:template>
  74. <xsl:template match="DRILL">
  75. <xsl:element name="drill">
  76. <xsl:attribute name="objectPath">
  77. <xsl:value-of select="@path"/>
  78. </xsl:attribute>
  79. <xsl:apply-templates select="*[name()='bus:parameters']"/>
  80. </xsl:element>
  81. </xsl:template>
  82. <xsl:template match="*[name()='bus:parameters']">
  83. <xsl:apply-templates select="*[name()='item']"/>
  84. </xsl:template>
  85. <xsl:template match="item[parent::node()[name()='bus:parameters']]">
  86. <xsl:element name="parameter">
  87. <xsl:attribute name="name"><xsl:value-of select="*[name()='bus:name']"/></xsl:attribute>
  88. <xsl:attribute name="type"><xsl:value-of select="*[name()='bus:type']"/></xsl:attribute>
  89. </xsl:element>
  90. </xsl:template>
  91. <!-- In the case of regular report data it looks like this
  92. <DR>
  93. <DRI >
  94. <OTI ></OTI>
  95. </DRI>
  96. </DR>
  97. In the case of drilled parameters the report data looks like this
  98. <DR>
  99. <DRI>
  100. <drillTargets>
  101. ... <drillTarget drillIdx="0">
  102. <drillParameter name="product" value="[great outdoors].[Products].[Products].[Product name]->:[PC].[@MEMBER].[30013]" displayValue="Star Gazer 2"/>
  103. </drillTarget>
  104. <OTI></OTI>
  105. </drillTargets>
  106. </DRI>
  107. </DR>
  108. So this match should accept both types
  109. -->
  110. <xsl:template match="OTI">
  111. <xsl:if test="not(contains(@style,'visibility:hidden'))">
  112. <xsl:element name="value">
  113. <xsl:if test="@RawXML != text()">
  114. <xsl:attribute name="rawValue"><xsl:value-of select="@RawXML"/></xsl:attribute>
  115. </xsl:if>
  116. <xsl:if test="normalize-space(.) = '' ">
  117. <xsl:attribute name="xs:nil">true</xsl:attribute>
  118. </xsl:if>
  119. <xsl:attribute name="presentationValue"><xsl:value-of select="text()"/></xsl:attribute>
  120. <!-- fix for bug 522357 - we grab the mun value from the drill trhrough results-->
  121. <xsl:for-each select="../drillTarget">
  122. <xsl:variable name="drillIndex">
  123. <xsl:value-of select="number(./@drillIdx) + 1"/>
  124. </xsl:variable>
  125. <xsl:variable name="drillValue">
  126. <xsl:choose>
  127. <xsl:when test="./drillParameter/@mun"><xsl:value-of select="./drillParameter/@mun"/></xsl:when>
  128. <xsl:when test="//DRILLS/DRILL[position()=$drillIndex]/*[name()='bus:parameters']/item/*[name()='bus:type'] = 'memberUniqueName'">
  129. <!--the value attribute contains a mun when the drill parameter is memberUniqueName -->
  130. <xsl:value-of select="./drillParameter/@value"/>
  131. </xsl:when>
  132. </xsl:choose>
  133. </xsl:variable>
  134. <xsl:element name="drillthrough">
  135. <xsl:attribute name="drillPosition"><xsl:value-of select="@drillIdx"/></xsl:attribute>
  136. <xsl:attribute name="drillValue"><xsl:value-of select="$drillValue"/></xsl:attribute>
  137. <xsl:attribute name="parameterName"><xsl:value-of select="./drillParameter/@name"/></xsl:attribute>
  138. </xsl:element>
  139. </xsl:for-each>
  140. </xsl:element>
  141. </xsl:if>
  142. </xsl:template>
  143. <xsl:template match="OIMG">
  144. <xsl:element name="value">
  145. <xsl:attribute name="presentationValue"><xsl:value-of select="@src"/></xsl:attribute>
  146. <!-- fix for bug 522357 - we grab the mun value from the drill trhrough results-->
  147. <xsl:for-each select=".//drillTarget">
  148. <xsl:variable name="drillIndex">
  149. <xsl:value-of select="number(./@drillIdx) + 1"/>
  150. </xsl:variable>
  151. <xsl:variable name="drillValue">
  152. <xsl:choose>
  153. <xsl:when test="./drillParameter/@mun"><xsl:value-of select="./drillParameter/@mun"/></xsl:when>
  154. <xsl:when test="//DRILLS/DRILL[position()=$drillIndex]/*[name()='bus:parameters']/item/*[name()='bus:type'] = 'memberUniqueName'">
  155. <!--the value attribute contains a mun when the drill parameter is memberUniqueName -->
  156. <xsl:value-of select="./drillParameter/@value"/>
  157. </xsl:when>
  158. </xsl:choose>
  159. </xsl:variable>
  160. <xsl:element name="drillthrough">
  161. <xsl:attribute name="drillPosition"><xsl:value-of select="@drillIdx"/></xsl:attribute>
  162. <xsl:attribute name="drillValue"><xsl:value-of select="$drillValue"/></xsl:attribute>
  163. <xsl:attribute name="parameterName"><xsl:value-of select="./drillParameter/@name"/></xsl:attribute>
  164. </xsl:element>
  165. </xsl:for-each>
  166. </xsl:element>
  167. </xsl:template>
  168. </xsl:stylesheet>