wsdl.xslt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Licensed Materials - Property of IBM
  4. IBM Cognos Products: cpscrn
  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. <!-- Cognos Web Services 7.3 -->
  9. <!-- Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. -->
  10. <!-- Cognos and the Cognos logo are trademarks of Cognos ULC, (formerly Cognos Incorporated). -->
  11. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  12. <xsl:variable name="info" select="/root/interface/discovery"/>
  13. <xsl:variable name="interface" select="/root/interface"/>
  14. <xsl:variable name="schemas" select="/root/schemas"/>
  15. <xsl:variable name="host" select="/root/http/param[@name = 'HTTP_HOST']"/>
  16. <xsl:variable name="script_name" select="/root/http/param[@name = 'SCRIPT_NAME']"/>
  17. <xsl:variable name="server" select="concat('http://', $host, $script_name, '/nav')"/>
  18. <xsl:output method="xml" encoding="iso-8859-1" indent="no"/>
  19. <xsl:template match="/">
  20. <xsl:apply-templates select="$info/wsdl:definitions"/>
  21. </xsl:template>
  22. <!-- This is needed to copy the appropriate namespaces into the output doc -->
  23. <xsl:template match="wsdl:definitions">
  24. <xsl:copy>
  25. <xsl:copy-of select="@*"/>
  26. <xsl:apply-templates select="$info/documentation"/>
  27. <xsl:apply-templates select="$info"/>
  28. </xsl:copy>
  29. </xsl:template>
  30. <xsl:template match="documentation">
  31. <wsdl:documentation>
  32. <xsl:value-of select="."/>
  33. </wsdl:documentation>
  34. </xsl:template>
  35. <xsl:template match="discovery">
  36. <xsl:variable name="definition" select="definition"/>
  37. <wsdl:types>
  38. <xsl:apply-templates select="documentation"/>
  39. <xsl:apply-templates select="$schemas/*" mode="copyroot"/>
  40. </wsdl:types>
  41. <!-- header messages -->
  42. <xsl:for-each select="$interface/header">
  43. <wsdl:message name="{ @name }">
  44. <xsl:for-each select="message/*">
  45. <wsdl:part>
  46. <xsl:copy-of select="@*"/>
  47. <xsl:apply-templates select="documentation"/>
  48. </wsdl:part>
  49. </xsl:for-each>
  50. </wsdl:message>
  51. </xsl:for-each>
  52. <!-- body messages -->
  53. <xsl:for-each select="$interface/operation[@internal != 'true']">
  54. <wsdl:message name="{ @name }">
  55. <xsl:for-each select="message/input">
  56. <wsdl:part name="request">
  57. <xsl:copy-of select="@*"/>
  58. <xsl:apply-templates select="documentation"/>
  59. </wsdl:part>
  60. </xsl:for-each>
  61. </wsdl:message>
  62. <wsdl:message name="{ @name }Response">
  63. <xsl:for-each select="message/output">
  64. <wsdl:part name="response">
  65. <xsl:copy-of select="@*"/>
  66. <xsl:apply-templates select="documentation"/>
  67. </wsdl:part>
  68. </xsl:for-each>
  69. </wsdl:message>
  70. <xsl:for-each select="message/fault">
  71. <xsl:if test="not(preceding::fault/@name = current()/@name)">
  72. <wsdl:message name="{ substring-after(@name, ':') }">
  73. <wsdl:part name="fault" element="{ @name }">
  74. <xsl:apply-templates select="documentation"/>
  75. </wsdl:part>
  76. </wsdl:message>
  77. </xsl:if>
  78. </xsl:for-each>
  79. </xsl:for-each>
  80. <wsdl:portType name="{ definition }Port">
  81. <xsl:for-each select="$interface/operation[@internal != 'true']">
  82. <wsdl:operation name="{ @name }">
  83. <xsl:apply-templates select="documentation"/>
  84. <wsdl:input message="tns:{ @name }"/>
  85. <wsdl:output message="tns:{ @name }Response"/>
  86. <xsl:for-each select="message/fault">
  87. <wsdl:fault message="{ @name }" name="{ substring-after(@name, ':') }">
  88. <xsl:apply-templates select="documentation"/>
  89. </wsdl:fault>
  90. </xsl:for-each>
  91. </wsdl:operation>
  92. </xsl:for-each>
  93. </wsdl:portType>
  94. <wsdl:binding name="{ definition }Binding" type="tns:{ definition }Port">
  95. <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  96. <xsl:for-each select="$interface/operation[not(@internal = 'true')]">
  97. <xsl:variable name="opname" select="@name"/>
  98. <wsdl:operation name="{ @name }">
  99. <soap:operation soapAction="{ $definition }.run"/>
  100. <wsdl:input>
  101. <soap:body use="literal"/>
  102. <xsl:for-each select="$interface/header/message/param">
  103. <xsl:variable name="prefix" select="substring-before(@element,':')"/>
  104. <soap:header message="tns:{ ../../@name }" part="{ @name }" use="literal" namespace="{ string($info/*[local-name()='definitions']/namespace::*[name()=$prefix])}" required="false"/>
  105. </xsl:for-each>
  106. </wsdl:input>
  107. <wsdl:output>
  108. <soap:body use="literal"/>
  109. <xsl:for-each select="$interface/header/message/param">
  110. <xsl:variable name="prefix" select="substring-before(@element,':')"/>
  111. <soap:header message="tns:{ ../../@name }" part="{ @name }" use="literal" namespace="{ string($info/*[local-name()='definitions']/namespace::*[name()=$prefix])}" required="false"/>
  112. </xsl:for-each>
  113. </wsdl:output>
  114. <xsl:for-each select="message/fault">
  115. <wsdl:fault name="{ substring-after(@name, ':') }">
  116. <soap:fault name="{ substring-after(@name, ':') }" use="literal">
  117. <xsl:apply-templates select="documentation"/>
  118. </soap:fault>
  119. </wsdl:fault>
  120. </xsl:for-each>
  121. </wsdl:operation>
  122. </xsl:for-each>
  123. </wsdl:binding>
  124. <wsdl:service name="{ definition }WebService">
  125. <wsdl:port name="{ definition }Port" binding="tns:{ definition }Binding">
  126. <soap:address location="{ $server }"/>
  127. </wsdl:port>
  128. </wsdl:service>
  129. </xsl:template>
  130. <xsl:template match="*" mode="copyroot">
  131. <xsl:copy>
  132. <xsl:copy-of select="@*"/>
  133. <xsl:copy-of select="*"/>
  134. </xsl:copy>
  135. </xsl:template>
  136. </xsl:stylesheet>