📄 wsdl2esd.xsl
字号:
<?xml version="1.0" encoding="UTF-8"?>
<!--
/////////////////////////////////////////////////////////////////////////////
// $Id: wsdl2esd.xsl,v 1.9 2001/08/09 00:08:12 rosimildo Exp $
//
// Copyright (c) 2001 - Rosimildo da Silva. All Rights Reserved.
//
// MODULE DESCRIPTION:
// XSL stylesheet to transform a WSDL to a, eSD( eSoap Service Description )
// document to be used by the eSoap C++ code generator.
//
// NOTE: This was inspired by some XSL document to trasnform WSDL documents
// into VB classes from ( www.vbxml.com )
//
// MODIFICATION/HISTORY:
//
// $Log: wsdl2esd.xsl,v $
// Revision 1.9 2001/08/09 00:08:12 rosimildo
// Small change to get style sheet working some generic prefix
// and not just "xsd".
//
//
// Created 2001/07/03 Rosimildo da Silva, ConnectTel Inc.
// [rdasilva@connecttel.com]
//
//////////////////////////////////////////////////////////////////////////////
-->
<xsl:stylesheet version="1.0"
xmlns:xsl ="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl ="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd ="http://www.w3.org/2001/XMLSchema"
xmlns:soap ="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:esd ="http://esd.esoapcg.com/esd/"
xmlns:cfg ="http://schemas.esoap.com/config/" >
<!-- Import the table with the Built-in types supported by eSoap -->
<xsl:variable name = "config" select="document('.\esoapcg.types')"/>
<!--
If a Master WSDL has an import element, get it.
FIXME: more than one <import> would make this for fail.
-->
<xsl:variable name = "g_import" select="document( /wsdl:definitions/wsdl:import/@location )"/>
<xsl:variable name = "g_definitions" select='$g_import/wsdl:definitions | /wsdl:definitions' />
<xsl:output method = "xml" indent ="yes"/>
<xsl:template match="wsdl:service">
<xsl:variable name="serviceName" select="@name"/>
<xsl:variable name="tpns" select ="$g_definitions/wsdl:types/xsd:schema/@targetNamespace" />
<xsl:variable name="tgtns" select="$g_definitions/@targetNamespace" />
<esd:Service name="{$serviceName}" xmlns:typens = "http://schemas.esoap.com/types/xsd"
xmlns="http://esd.esoapcg.com/esd/"
targetNamespace ="{$tgtns}"
typeNamespace="{$tpns}" >
<!-- process the complex types of the WSDL file -->
<xsl:for-each select="$g_definitions/wsdl:types/xsd:schema/xsd:complexType">
<xsl:call-template name="outputType">
</xsl:call-template>
</xsl:for-each>
<!-- process each port as one interface -->
<xsl:for-each select="wsdl:port">
<xsl:call-template name="processPort">
<xsl:with-param name="serviceName" select="$serviceName"/>
</xsl:call-template>
</xsl:for-each>
</esd:Service>
</xsl:template>
<!-- Process and PORT, and create the Interface elements of the eSD document -->
<xsl:template name="processPort">
<xsl:param name="serviceName"/>
<xsl:variable name="portName" select=" substring-after( $g_definitions/wsdl:binding[@name=substring-after( current()/@binding,':')]/@type, ':' )" />
<xsl:variable name="sa" select="$g_definitions/wsdl:binding[$portName=substring-after(@type,':')]/wsdl:operation[last()]/soap:operation/@soapAction" />
<xsl:variable name="ns" select="$g_definitions/wsdl:binding[$portName=substring-after(@type,':')]/wsdl:operation[last()]/wsdl:input/soap:body/@namespace" />
<xsl:variable name="lo" select="current()/soap:address/@location" />
<xsl:variable name="tpns" select="$g_definitions/wsdl:types/xsd:schema/@targetNamespace" />
<esd:Interface name ="{$portName}" soapAction ="{$sa}" namespace ="{$ns}" typens ="{$tpns}" location ="{$lo}">
<!-- get the operations for this portType -->
<xsl:for-each select="$g_definitions/wsdl:portType[@name=$portName]/wsdl:operation">
<!-- output a method -->
<xsl:call-template name="outputOperation">
<xsl:with-param name="serviceName" select="$serviceName"/>
<xsl:with-param name="portName" select="$portName"/>
</xsl:call-template>
</xsl:for-each>
</esd:Interface>
</xsl:template>
<xsl:template name="outputOperation">
<xsl:param name="serviceName"/>
<xsl:param name="portName"/>
<xsl:variable name="operationName" select="@name"/>
<!-- message names without namespace prefix -->
<xsl:variable name="inMsgName" select="substring-after(wsdl:input/@message,':')"/>
<xsl:variable name="outMsgName" select="substring-after(wsdl:output/@message,':')"/>
<xsl:variable name="inMsg" select="$g_definitions/wsdl:message[@name=$inMsgName]"/>
<xsl:variable name="outMsg" select="$g_definitions/wsdl:message[@name=$outMsgName]"/>
<xsl:variable name="isFunction" select="$outMsg/wsdl:part[@name='Result']"/>
<esd:Method name="{$operationName}" >
<!-- process the IN parameters -->
<esd:InParam name="{$inMsg/@name}">
<xsl:for-each select="$inMsg/wsdl:part">
<xsl:variable name="inOut" select='boolean( $outMsg/wsdl:part[@name=current()/@name] )'/>
<xsl:call-template name="outputItem">
<xsl:with-param name="inOut" select="$inOut"/>
</xsl:call-template>
</xsl:for-each>
</esd:InParam>
<!-- process the OUT parameters -->
<esd:OutParam name="{$outMsg/@name}">
<xsl:for-each select="$outMsg/wsdl:part">
<xsl:variable name="inOut" select='boolean( $inMsg/wsdl:part[@name=current()/@name] )'/>
<xsl:call-template name="outputItem">
<xsl:with-param name="inOut" select="$inOut"/>
</xsl:call-template>
</xsl:for-each>
</esd:OutParam>
</esd:Method>
</xsl:template>
<xsl:template name="outputType">
<xsl:variable name="typeName" select="@name"/>
<!-- message names without namespace prefix -->
<xsl:variable name="isBuiltin" select="$config/cfg:config/cfg:typeMap/cfg:type[@name=current()/@type]/cfg:esoapType"/>
<xsl:variable name="sType" select='substring-before( current()/xsd:complexContent/xsd:restriction/xsd:attribute/@wsdl:arrayType, "[" )' />
<xsl:variable name="arType" select="current()/xsd:complexContent/xsd:restriction/xsd:attribute/@wsdl:arrayType" />
<xsl:variable name="isArray" select='boolean( current()/xsd:complexContent/xsd:restriction[@base="SOAP-ENC:Array"] )' />
<xsl:variable name="arBuiltin" select="$config/cfg:config/cfg:typeMap/cfg:type[@name=$sType]/cfg:esoapType"/>
<xsl:choose><xsl:when test="$isArray">
<xsl:choose><xsl:when test="$arBuiltin">
<esd:AType name ="{$typeName}"
builtin="{boolean($arBuiltin)}"
type ="{$arType}"
stype ="{$sType}" />
</xsl:when><xsl:otherwise>
<esd:AType name ="{$typeName}"
builtin="{boolean($arBuiltin)}"
type ="{concat('typens:', substring-after( $arType, ':' ) ) }"
stype ="{concat('typens:', substring-after( $sType, ':' ) ) }" />
</xsl:otherwise></xsl:choose>
</xsl:when><xsl:otherwise>
<esd:CType name="{$typeName}" type="{@type}" >
<!-- process the items -->
<xsl:for-each select="current()/xsd:sequence/xsd:element | current()/xsd:all/xsd:element">
<xsl:call-template name="outputItem">
<xsl:with-param name="inOut" select="boolean( 0 )"/>
</xsl:call-template>
</xsl:for-each>
</esd:CType>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Basic Template to write an Item for a function or a type -->
<xsl:template name="outputItem">
<xsl:param name="inOut" />
<xsl:variable name="isTypeBuiltin_1" select='$config/cfg:config/cfg:typeMap/cfg:type[@name=current()/@type]/cfg:esoapType'/>
<xsl:variable name="isTypeBuiltin_2" select='$config/cfg:config/cfg:typeMap/cfg:type[@name=substring-after( current()/@type, ":" )]/cfg:esoapType'/>
<xsl:variable name="isFuncBuiltin" select='boolean( $isTypeBuiltin_1 | $isTypeBuiltin_2 )'/>
<xsl:variable name="ctType" select='$g_definitions/wsdl:types/xsd:schema/xsd:complexType[@name= substring-after( current()/@type, ":" ) ]' />
<xsl:variable name="aType" select='$ctType/xsd:complexContent/xsd:restriction/xsd:attribute/@wsdl:arrayType' />
<xsl:variable name="newType" select="substring-before( $aType, '[' )"/>
<xsl:variable name="arBuiltin_1" select='$config/cfg:config/cfg:typeMap/cfg:type[@name=$newType]/cfg:esoapType'/>
<xsl:variable name="arBuiltin_2" select='$config/cfg:config/cfg:typeMap/cfg:type[@name=substring-after( $newType, ":" )]/cfg:esoapType'/>
<xsl:variable name="arBuiltin" select='boolean( $arBuiltin_1 | $arBuiltin_2 )'/>
<xsl:variable name="ns_atype" select='contains( $newType, ":" )' />
<xsl:variable name="ns_type" select='contains( @type, ":" )' />
<xsl:variable name="no_ns" select='substring-after( @type, ":" )' />
<xsl:variable name="no_ans" select='substring-after( $newType, ":" )' />
<!-- Check for an array type -->
<xsl:choose><xsl:when test="$aType">
<xsl:choose><xsl:when test="$arBuiltin">
<xsl:choose><xsl:when test="$ns_atype">
<esd:item name ="{@name}"
type ="{concat('xsd:', $no_ans )}"
builtin ="{$arBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:when><xsl:otherwise>
<esd:item name ="{@name}"
type ="{concat('xsd:', $newType ) }"
builtin ="{$arBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:otherwise></xsl:choose>
</xsl:when><xsl:otherwise>
<xsl:choose><xsl:when test="$ns_atype">
<esd:item name ="{@name}"
type ="{concat('typens:', $no_ans )}"
builtin ="{$arBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:when><xsl:otherwise>
<esd:item name ="{@name}"
type ="{concat('typens:', $newType ) }"
builtin ="{$arBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:otherwise></xsl:choose>
</xsl:otherwise></xsl:choose>
</xsl:when><xsl:otherwise>
<!-- It is NOT array -->
<xsl:choose><xsl:when test="$isFuncBuiltin">
<xsl:choose><xsl:when test="$ns_type">
<esd:item name ="{@name}"
type ="{concat('xsd:', $no_ns )}"
builtin ="{$isFuncBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:when><xsl:otherwise>
<esd:item name ="{@name}"
type ="{concat('xsd:', @type )}"
builtin ="{$isFuncBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:otherwise></xsl:choose>
</xsl:when><xsl:otherwise>
<xsl:choose><xsl:when test="$ns_type">
<esd:item name ="{@name}"
type ="{concat('typens:', $no_ns )}"
builtin ="{$isFuncBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:when><xsl:otherwise>
<esd:item name ="{@name}"
type ="{concat('typens:', @type )}"
builtin ="{$isFuncBuiltin}"
array = "{boolean( $aType )}"
inout ="{$inOut}" />
</xsl:otherwise></xsl:choose>
</xsl:otherwise></xsl:choose>
</xsl:otherwise></xsl:choose>
</xsl:template>
</xsl:stylesheet>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -