WEB开发网
开发学院软件开发Python Python Web 服务开发人员: 三股力量:Python、Web... 阅读

Python Web 服务开发人员: 三股力量:Python、Web 服务和 XSLT

 2008-09-30 13:02:15 来源:WEB开发网   
核心提示: 清单 5提供了一个为端点用户呈现有用信息的 XSLT 脚本,它是从先前的 developerWorks 文章“WSDL processing with XSLT”(请参阅 参考资料)中所开发的一个转换改编而来的,Python Web 服务开发人员: 三股力量:Pyt

清单 5提供了一个为端点用户呈现有用信息的 XSLT 脚本。它是从先前的 developerWorks 文章“WSDL processing with XSLT”(请参阅 参考资料)中所开发的一个转换改编而来的。它使用了许多自由方式(liberty)和快捷方式(尤其是在它处理 WSDL 上下文中的限定名时),但它也许可用于目前使用的大多数 WSDL 1.1 文件。

清单 5. XSLT 脚本

<?xml version="1.0" encoding="utf-8"?>
<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/"
>
 <xsl:output method='html'/>
 <!-- Lookup tables for messages, portTypes, bindings and services -->
 <xsl:key name='message' match="wsdl:definitions/wsdl:message"
      use='@name'/>
 <xsl:key name='port-type' match="wsdl:definitions/wsdl:portType"
      use='@name'/>
 <xsl:key name='binding' match="wsdl:definitions/wsdl:binding"
      use='@name'/>
 <xsl:key name='service' match="wsdl:definitions/wsdl:service"
      use='@name'/>
 <xsl:template match='/'>
  <html>
  <head>
   <title>
Service summary: <xsl:value-of select='wsdl:definitions/@name'/>
   </title>
   <meta http-equiv="content-type" content="text/html"
      charset="UTF-8"/>
  </head>
  <body>
    <h1>
Service summary: <xsl:value-of select='wsdl:definitions/@name'/>
    </h1>
    <p><xsl:value-of select='wsdl:definitions/@documentation'/></p>
    <xsl:apply-templates select="wsdl:definitions/wsdl:service"/>
  </body>
   </html>
  </xsl:template>
  <xsl:template match='wsdl:service'>
   <div style="background: #ccffff">
    Service "<xsl:value-of select='@name'/>" hosted at
   <code>
    <xsl:value-of select='wsdl:port/soap:address/@location'/>
   </code>
    <xsl:variable name="binding"
     select="key('binding',
           substring-after(wsdl:port/@binding, ':'))"
    />
    <xsl:variable name="port-type"
     select="key('port-type',
           substring-after($binding/@type, ':'))"
    />
    <xsl:apply-templates select="$port-type/wsdl:operation"/>
   </div>
  </xsl:template>
 <xsl:template match='wsdl:operation'>
  <p>Operation "<b><xsl:value-of select='@name'/></b>" message details:</p>
  <!-- Yes, should sue CSS, but keep this example simple -->
  <table border="1" width="50%">
   <tbody>
    <xsl:if test="wsdl:input">
     <xsl:call-template name='message-role'>
      <xsl:with-param name="role-node" select="wsdl:input"/>
     </xsl:call-template>
    </xsl:if>
    <xsl:if test="wsdl:output">
     <xsl:call-template name='message-role'>
      <xsl:with-param name="role-node" select="wsdl:output"/>
     </xsl:call-template>
    </xsl:if>
    <xsl:if test="wsdl:fault">
     <xsl:call-template name='message-role'>
      <xsl:with-param name="role-node" select="wsdl:fault"/>
     </xsl:call-template>
    </xsl:if>
   </tbody>
  </table>
 </xsl:template>
 <xsl:template name='message-role'>
  <xsl:param name="role-node"/>
  <xsl:variable name="role-name"
         select="local-name($role-node)"/>
  <xsl:variable name="message"
   select="key('message',
       substring-after($role-node/@message, ':'))"
   />
  <tr>
   <td><xsl:value-of select='$role-name'/></td>
   <td>
    <table width="100%">
     <xsl:apply-templates select="$message/wsdl:part"/>
    </table>
   </td>
  </tr>
 </xsl:template>
 <xsl:template match='wsdl:part'>
  <tr>
   <td width="50%"><b><xsl:value-of select='@name'/></b></td>
   <td><xsl:value-of select='@type'/></td>
  </tr>
 </xsl:template>
</xsl:stylesheet>

上一页  1 2 3 4 5 6 7  下一页

Tags:Python Web 服务

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接