<?xml version="1.0"?>
 <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/"
   xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
   xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
   xmlns:x="http://namespaces.ogbuji.net/articles"
   xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 >

   <xsl:param name="rule_type" >sequence</xsl:param>
   <xsl:param name="file_name" >rendezvous.html</xsl:param>

   <xsl:output method='html'/>

   <xsl:template match='/'>
     <HTML>
     <HEAD>
       <TITLE>Service Definition: <xsl:value-of select='wsdl:definitions/@name'/></TITLE>
       <META HTTP-EQUIV="content-type" content="text/html" charset="UTF-8"/>
     </HEAD>
     <BODY STYLE="background: #ffffff">
       <xsl:apply-templates select="/wsdl:definitions"/>
       <xsl:for-each select="wsdl:definitions/wsdl:service">
         <center>
            <p><font size="6">Service name: <xsl:value-of select='@name'/></font>   </p> 
         </center>

         <table border="1" width="100%" bgcolor="#CCCCFF" bordercolor="#000000">
          
            <xsl:apply-templates select="wsdl:port"/>

         </table>

       
       </xsl:for-each>
       <xsl:apply-templates select="wsdl:definitions/wsdl:types"/>
     </BODY>
     </HTML>
   </xsl:template>
   
   <xsl:template match="wsdl:definitions">
      <I><xsl:value-of select='wsdl:documentation'/></I>
   </xsl:template>

   <xsl:template match="wsdl:port">
      <xsl:variable name='binding_name' select="substring-after(@binding,':')"/>      
      <tr>
         <td>
            <b><font size="4">Binding name: <xsl:value-of select="substring-after(@binding,':')"/></font></b><br></br>
            <b><font size="4">Locations: 
                  <xsl:apply-templates select="wsdlsoap:address"/>
               </font>
            </b><br></br>
         <table border="1" width="100%" bgcolor='#CCCCC' bodercolor='#999999'>
            <xsl:apply-templates  select="/wsdl:definitions/wsdl:binding[attribute::name=$binding_name]"/> 
         </table>
         </td>
      </tr>

   </xsl:template>

   <xsl:template match="wsdlsoap:address">
      <xsl:value-of select='@location'/>,
   </xsl:template>

   <xsl:template match="wsdl:binding">
      <th align="left" colspan="2">
        <xsl:apply-templates select="wsdlsoap:binding"/>  
            <b>Method Descriptions:</b>
        <xsl:if test="wsdl:documentation">
        <br></br>
        <br></br>
        </xsl:if>
        <I><xsl:value-of select='wsdl:documentation'/></I>
      </th>
        <xsl:variable name="port_type" select="substring-after(@type,':')"/>
        <xsl:apply-templates select="/wsdl:definitions/wsdl:portType[attribute::name=$port_type]/wsdl:operation"/>
   </xsl:template>

   <xsl:template match="wsdlsoap:binding">
            <i>Binding style: <xsl:value-of select='@style'/>, 
               Binding transport: <xsl:value-of select='@transport'/>
            </i>
         <br></br>
   </xsl:template>

   <xsl:template match="wsdl:operation">
      <tr>
           <td width="300pt">
              <xsl:apply-templates select="wsdl:output"/>
           </td>
           <td>
              <xsl:value-of select='@name'/>(
              <xsl:apply-templates select="wsdl:input"/>
              )
              <xsl:if test="wsdl:documentation">
              <br></br>
              <br></br>
              </xsl:if>
              <I><xsl:value-of select='wsdl:documentation'/></I>
           </td>
      </tr>
   </xsl:template>

   <xsl:template match="wsdl:input">
       <xsl:variable name='input_name' select="@name"/>      
       <xsl:apply-templates  select="/wsdl:definitions/wsdl:message[attribute::name=$input_name]"/> 
   </xsl:template>

   <xsl:template match="wsdl:message">
        <xsl:apply-templates select="wsdl:part"/>
   </xsl:template>

   <xsl:template match="wsdl:part">
        <xsl:if test="attribute::type">
           <xsl:if test="attribute::type[contains(.,'xsd:string')]">
               <xsl:value-of select="@type"/> <xsl:text> </xsl:text><xsl:value-of select='@name'/>
           </xsl:if>
           <xsl:if test="attribute::type[contains(.,'xsd:int')]">
               <xsl:value-of select="@type"/> <xsl:text> </xsl:text><xsl:value-of select='@name'/>
           </xsl:if>
           <xsl:if test="boolean( attribute::type[not(contains(.,'xsd:string'))] and attribute::type[not(contains(.,'xsd:int'))] )">
               <xsl:variable name="link_name1" select="substring-after(@type,':')"/> 
               <xsl:variable name="link_name2" select="@type"/> 
               <a href="{$file_name}#{$link_name1}">  <xsl:value-of select="$link_name2"/> </a> <xsl:text> </xsl:text><xsl:value-of select='@name'/>
           </xsl:if>
           <xsl:if test="attribute::nillable">
                <xsl:if test="attribute::nillable[contains(.,'true')]">
                    ^[0,1] 
                </xsl:if>
           </xsl:if>
           ,
        </xsl:if>
   </xsl:template>
 
   <xsl:template match="wsdl:output">
       <xsl:variable name='output_name' select="@name"/>      
            <xsl:apply-templates  select="/wsdl:definitions/wsdl:message[attribute::name=$output_name]"/> 
       <xsl:if test="wsdl:documentation">
          <xsl:if test="wsdl:documentation">
          <br></br>
          <br></br>
          </xsl:if>
       </xsl:if>
       <I><xsl:value-of select='wsdl:documentation'/></I>
   </xsl:template>

   <xsl:template match="wsdl:types">
      <xsl:apply-templates select="wsdl:schema"/>
   </xsl:template>

   <xsl:template match="wsdl:schema">
      <br></br>
      <table border="1" width="100%" bgcolor="#CCCCFF" bordercolor="#000000">
        <xsl:apply-templates select="wsdl:complexType"/>
        <xsl:apply-templates select="wsdl:simpleType"/>
      </table>
   </xsl:template>
        
   <xsl:template match="wsdl:complexType">
      <xsl:if test="@name">
      <tr>
         <td>
            <xsl:variable name='type_name' select="@name"/>
            <a name="{$type_name}"> <xsl:value-of select="$type_name"/> </a>
            <xsl:if test="wsdl:restriction">
                <xsl:apply-templates select="wsdl:restriction"/> 
                --> 
            </xsl:if>
            <xsl:if test="wsdl:complexContent">
                --> 
                <xsl:apply-templates select="wsdl:complexContent"/> 
            </xsl:if>
            <xsl:if test="wsdl:sequence">
                 -->
                 <xsl:apply-templates select="wsdl:sequence"/> 
            </xsl:if>
            <xsl:if test="wsdl:documentation">
               <xsl:if test="wsdl:documentation">
               <br></br>
               <br></br>
               </xsl:if>
            </xsl:if>
            <I><xsl:value-of select='wsdl:documentation'/></I>
         </td>
      </tr>
      </xsl:if>
      <xsl:if test="not(@name)">
         (
         <xsl:if test="wsdl:all">
             <xsl:apply-templates select="wsdl:all"/> 
         </xsl:if>
         )
      </xsl:if>
   </xsl:template>

   <xsl:template match="wsdl:all">
        <xsl:if test="wsdl:element">
          <xsl:apply-templates select="wsdl:element"/> 
        </xsl:if>

   </xsl:template>

   <xsl:template match="wsdl:simpleType">
      <tr>
         <td>
            <xsl:variable name='type_name' select="@name"/>
            <a name="{$type_name}"><xsl:text>  </xsl:text><xsl:value-of select="$type_name"/> </a><xsl:text> </xsl:text>
            <xsl:if test="wsdl:restriction">
                -->
                <xsl:apply-templates select="wsdl:restriction"/> 
            </xsl:if>
            <xsl:if test="wsdl:documentation">
            <br></br>
            <br></br>
            </xsl:if>
            <I><xsl:value-of select='wsdl:documentation'/></I>
         </td>
      </tr> 
   </xsl:template>

   <xsl:template match="wsdl:complexContent">
        <xsl:if test="wsdl:restriction">
            <xsl:apply-templates select="wsdl:restriction"/> 
        </xsl:if>
        <xsl:if test="wsdl:extension">
            <xsl:apply-templates select="wsdl:extension"/> 
        </xsl:if>
        <xsl:if test="wsdl:sequence">
            <xsl:apply-templates select="wsdl:sequence"/> 
        </xsl:if>
   </xsl:template>
    
   <xsl:template match="wsdl:restriction">
        (
        <xsl:value-of select="@base"/> [R]:: 
        <xsl:if test="wsdl:attribute">
            <xsl:apply-templates select="wsdl:attribute"/> 
        </xsl:if>
        <xsl:if test="wsdl:enumeration">
             ENUM[
        </xsl:if>
            <xsl:apply-templates select="wsdl:enumeration"/> 
        <xsl:if test="wsdl:enumeration">
             ]
        </xsl:if>
        <xsl:if test="wsdl:sequence">
            <xsl:apply-templates select="wsdl:sequence"/> 
        </xsl:if>
        )
   </xsl:template>

   <xsl:template match="wsdl:extension">
        (
        <xsl:value-of select="@base"/> [E]::
        <xsl:if test="wsdl:attribute">
            <xsl:apply-templates select="wsdl:attribute"/> 
        </xsl:if>
        <xsl:if test="wsdl:sequence">
            <xsl:apply-templates select="wsdl:sequence"/> 
        </xsl:if>
        <xsl:if test="wsdl:enumeration">
             ENUM[
        </xsl:if>
            <xsl:apply-templates select="wsdl:enumeration"/> 
        <xsl:if test="wsdl:enumeration">
             ]
        </xsl:if>
        )
   </xsl:template>

   <xsl:template match="wsdl:enumeration">
        <xsl:value-of select="@value"/>,
   </xsl:template>
   
   <xsl:template match="wsdl:attribute">
        <xsl:if test="@wsdl:arrayType">
            <xsl:variable name='array_ref1' select="substring-after(@wsdl:arrayType,':')"/>      
            <xsl:variable name='array_ref2' select="substring-before($array_ref1,'[]')"/>
            <xsl:if test="boolean( attribute::wsdl:arrayType[starts-with(.,'impl')])">
               <a href="{$file_name}#{$array_ref2}">  <xsl:value-of select="@wsdl:arrayType"/> </a> 
            </xsl:if>
            <xsl:if test="not(boolean( attribute::wsdl:arrayType[starts-with(.,'impl')]))">
               <xsl:value-of select="@wsdl:arrayType"/> 
            </xsl:if>
        </xsl:if>
          
   </xsl:template>

   <xsl:template match="wsdl:sequence">
        {
        <xsl:if test="wsdl:element">
            <xsl:apply-templates select="wsdl:element"/> 
        </xsl:if>
        <xsl:if test="wsdl:choice">
            (
            <xsl:apply-templates select="wsdl:choice"/>
            ),
        </xsl:if>
        }
        <xsl:if test="@minOccurs">
             ^[<xsl:value-of select="@minOccurs"/>,
        </xsl:if>
        <xsl:if test="boolean( @maxOccurs and not(@minOccurs))">
              ^[0,
        </xsl:if>
                
        <xsl:if test="@maxOccurs">
           <xsl:if test="boolean( attribute::maxOccurs[contains(.,'unbounded')])">
              *]
           </xsl:if>
           <xsl:if test="boolean( attribute::maxOccurs[not(contains(.,'unbounded'))])">
              <xsl:value-of select="@maxOccurs"/> ] 
           </xsl:if>
        </xsl:if>
        <xsl:if test="boolean( not(@maxOccurs) and @minOccurs )">
              *] 
        </xsl:if>
         
   </xsl:template>

   <xsl:template match="wsdl:choice">
        <xsl:apply-templates select="wsdl:element">
            <xsl:with-param name="nr_of_entries"><xsl:value-of select="count(wsdl:element)"/></xsl:with-param>
            <xsl:with-param name="rule_type" >choice</xsl:with-param>
        </xsl:apply-templates>
   </xsl:template>

   <xsl:template match="wsdl:element" name="element">
        <xsl:param name="rule_type" >sequence</xsl:param>
        <xsl:param name="nr_of_entries" >1</xsl:param>
        <xsl:if test="@type">
            <xsl:if test="boolean( attribute::type[starts-with(.,'impl')])">
                <xsl:variable name='type_ref' select="substring-after(@type,':')"/>      
                <a href="{$file_name}#{$type_ref}">  <xsl:value-of select="@type"/> </a> 
            </xsl:if>
            <xsl:if test="not(boolean( attribute::type[starts-with(.,'impl')]))">
               <xsl:value-of select="@type"/> 
            </xsl:if>
        </xsl:if>
        <xsl:if test="wsdl:complexType">
            <xsl:apply-templates select="wsdl:complexType"/>
        </xsl:if>
        <xsl:text> </xsl:text>
        <xsl:if test="@name">
            <xsl:value-of select="@name"/> 
        </xsl:if>
        
        <xsl:if test="@minOccurs">
             ^[<xsl:value-of select="@minOccurs"/>,
        </xsl:if>

        <xsl:if test="boolean( @maxOccurs and not(@minOccurs))">
              ^[0,
        </xsl:if>
                
        <xsl:if test="@maxOccurs">
           <xsl:if test="boolean( attribute::maxOccurs[contains(.,'unbounded')])">
              *]
           </xsl:if>
           <xsl:if test="boolean( attribute::maxOccurs[not(contains(.,'unbounded'))])">
              <xsl:value-of select="@maxOccurs"/> ] 
           </xsl:if>
        </xsl:if>
        <xsl:if test="boolean( not(@maxOccurs) and @minOccurs )">
              *] 
        </xsl:if>

        <xsl:if test="@nillable">
           <xsl:if test="boolean( attribute::nillable[contains(.,'true')])">
              <xsl:if test="@minOccurs">
                <xsl:if test="not(boolean( attribute::minOccurs[contains(.,'0')]))">
                  |0      
                </xsl:if>
              </xsl:if>
              <xsl:if test="boolean( not(@maxOccurs) and not(@minOccurs))">
                 ^[0,1]
              </xsl:if>
           </xsl:if>
        </xsl:if>
        <xsl:if test="$rule_type = 'choice'">
           <xsl:if test="not(position() = $nr_of_entries)">
           |
           </xsl:if>
        </xsl:if>
        <xsl:if test="$rule_type = 'sequence'">
           ,
        </xsl:if>
           
   
   </xsl:template>
   
 
</xsl:stylesheet>













