Search code examples
xsltxsdwsdlextractchaining

XSLT chaining or combining xsl:copy-of and xsl:copy


I've got the following two XSL transforms that I would like to chain together in one XSL file.

The first transform:

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
<xsl:template match="/">
  <xsl:copy-of select="/s0:definitions/s0:types/xs:schema"/>
</xsl:template>
</xsl:stylesheet>

And the second transform (using the output of the first as input):

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="/xs:schema/xs:element[@name='ServiceAuth']"/>
<xsl:template match="/xs:schema/xs:import[@namespace='http://www.somecompany.com/serviceAuth/ ']"/>
</xsl:stylesheet>

What I'm aiming to accomplish with this, is to copy only the xs:schema node (and all it's children) from a WSDL whilst at the same time removing two nodes from inside the xs:schema node.

How do I chain these two together in one XSL or is there an even better way to accomplish the above objective?

Below is the WSDL input file that should serve as input to the first transform:

<s0:definitions name="CBS_GetUpgradeEligibility" targetNamespace="http://www.somecompany.com/" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://www.somecompany.com/CBS_GetUpgradeEligibility/" xmlns:s2="http://www.somecompany.com/" xmlns:s3="http://schemas.xmlsoap.org/wsdl/soap/">
   <s0:types>
      <xs:schema targetNamespace="http://www.somecompany.com/CBS_GetUpgradeEligibility/" xmlns:auth="http://www.somecompany.com/serviceAuth/" xmlns:cbs="http://www.somecompany.com/CBS_GetUpgradeEligibility/" xmlns:esb="http://www.somecompany.com/esbTypes/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.somecompany.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
         <xs:import namespace="http://www.somecompany.com/esbTypes/" schemaLocation="http://127.0.0.1:5000/CBS_GetUpgradeEligibility?SCHEMA%2FVodacom+Services%2FInfrastructure+Services%2FSchemas%2FXSD_ESBTypes"/>
         <xs:import namespace="http://www.somecompany.com/serviceAuth/ " schemaLocation="http://127.0.0.1:5000/CBS_GetUpgradeEligibility?SCHEMA%2FVodacom+Services%2FInfrastructure+Services%2FSchemas%2FXSD_ServiceAuth"/>
         <xs:simpleType name="DESTINATION_MSISDN">
            <xs:restriction base="xs:string">
               <xs:maxLength value="11"/>
            </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="STRING_13">
            <xs:restriction base="xs:string">
               <xs:maxLength value="13"/>
            </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="STRING_20">
            <xs:restriction base="xs:string">
               <xs:maxLength value="20"/>
            </xs:restriction>
         </xs:simpleType>
         <xs:complexType name="UPGRADE_TYPE_DETAILS">
            <xs:sequence>
               <xs:element maxOccurs="1" minOccurs="1" name="isber" type="cbs:STRING_13"/>
               <xs:element maxOccurs="1" minOccurs="1" name="isreward" type="cbs:STRING_13"/>
               <xs:element maxOccurs="1" minOccurs="1" name="code" type="cbs:STRING_20"/>
            </xs:sequence>
         </xs:complexType>
         <xs:complexType name="QUALIFIES_FOR_UPGRADE_DETAILS">
            <xs:sequence>
               <xs:element maxOccurs="1" minOccurs="1" name="isaveragespentmet" type="cbs:STRING_13"/>
               <xs:element maxOccurs="1" minOccurs="1" name="is7daypremature" type="cbs:STRING_13"/>
               <xs:element maxOccurs="1" minOccurs="1" name="upgradepossible" type="cbs:STRING_13"/>
               <xs:element maxOccurs="1" minOccurs="1" name="upgradeduedate" type="cbs:STRING_13"/>
               <xs:element maxOccurs="1" minOccurs="0" name="UpgradeType" type="cbs:UPGRADE_TYPE_DETAILS"/>
            </xs:sequence>
         </xs:complexType>
         <xs:element name="ServiceAuth">
            <xs:complexType>
               <xs:sequence>
                  <xs:element name="Username" type="auth:Username"/>
                  <xs:element name="Password" type="auth:Password"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="GetUpgradeEligibilityRequest">
            <xs:complexType>
               <xs:sequence>
                  <xs:element name="TSORequest" type="cbs:getUpgradeEligibilityRequestElement"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:element name="GetUpgradeEligibilityResponse">
            <xs:complexType>
               <xs:sequence>
                  <xs:element maxOccurs="1" minOccurs="1" name="TSOID" type="esb:TSOID"/>
                  <xs:element name="TSOResponse" type="cbs:getUpgradeEligibilityResponseElement"/>
                  <xs:element maxOccurs="1" minOccurs="1" name="TSOResult" type="esb:TSOResult"/>
               </xs:sequence>
            </xs:complexType>
         </xs:element>
         <xs:complexType name="getUpgradeEligibilityRequestElement">
            <xs:sequence>
               <xs:element maxOccurs="1" minOccurs="1" name="MSISDN" type="cbs:DESTINATION_MSISDN"/>
            </xs:sequence>
         </xs:complexType>
         <xs:complexType name="getUpgradeEligibilityResponseElement">
            <xs:sequence>
               <xs:element maxOccurs="1" minOccurs="1" name="MSISDN" type="cbs:DESTINATION_MSISDN"/>
               <xs:element maxOccurs="1" minOccurs="1" name="QualifiesForUpgrade" type="cbs:QUALIFIES_FOR_UPGRADE_DETAILS"/>
            </xs:sequence>
         </xs:complexType>
      </xs:schema>
   </s0:types>
   <s0:message name="GetUpgradeEligibilityRequestMessage">
      <s0:part element="s1:ServiceAuth" name="ServiceAuth"/>
      <s0:part element="s1:GetUpgradeEligibilityRequest" name="GetUpgradeEligibilityRequest"/>
   </s0:message>
   <s0:message name="GetUpgradeEligibilityResponseMessage">
      <s0:part element="s1:GetUpgradeEligibilityResponse" name="GetUpgradeEligibilityResponse"/>
   </s0:message>
   <s0:portType name="esbTransactionPort">
      <s0:operation name="getUpgradeEligibility">
         <s0:input message="s2:GetUpgradeEligibilityRequestMessage"/>
         <s0:output message="s2:GetUpgradeEligibilityResponseMessage"/>
      </s0:operation>
   </s0:portType>
   <s0:binding name="getUpgradeEligibilityEsbTransactionBinding" type="s2:esbTransactionPort">
      <s3:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <s0:operation name="getUpgradeEligibility">
         <s3:operation soapAction="" style="document"/>
         <s0:input>
            <s3:header message="s2:GetUpgradeEligibilityRequestMessage" part="ServiceAuth" use="literal"/>
            <s3:body parts="GetUpgradeEligibilityRequest" use="literal"/>
         </s0:input>
         <s0:output>
            <s3:body parts="GetUpgradeEligibilityResponse" use="literal"/>
         </s0:output>
      </s0:operation>
   </s0:binding>
   <s0:service name="getUpgradeEligibilityEsbTransactionBindingQSService">
      <s0:port binding="s2:getUpgradeEligibilityEsbTransactionBinding" name="getUpgradeEligibilityEsbTransactionBindingQSPort">
         <s3:address location="http://VESB14-PRD:7701/CBS_GetUpgradeEligibility"/>
      </s0:port>
   </s0:service>
</s0:definitions>

Solution

  • If you want a third stylesheet that compose those two performing the same transformation as:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:s0="http://schemas.xmlsoap.org/wsdl/">
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="/">
            <xsl:apply-templates select="s0:definitions/s0:types/xs:schema"/>
        </xsl:template>
        <xsl:template match="xs:schema/xs:element[@name='ServiceAuth']"/>
        <xsl:template match="xs:schema/xs:import[@namespace='http://www.somecompany.com/serviceAuth/']"/>
    </xsl:stylesheet>
    

    Then you need:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxsl="urn:schemas-microsoft-com:xslt">
        <xsl:import href="stylesheet2.xsl"/>
        <xsl:import href="stylesheet1.xsl"/>
        <xsl:template match="/">
            <xsl:variable name="vFirst">
                <xsl:apply-imports/>
            </xsl:variable>
            <xsl:apply-templates select="msxsl:node-set($vFirst)/node()"/>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <xs:schema targetNamespace="http://www.somecompany.com/CBS_GetUpgradeEligibility/" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="http://www.somecompany.com/CBS_GetUpgradeEligibility/" xmlns:s2="http://www.somecompany.com/" xmlns:s3="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:auth="http://www.somecompany.com/serviceAuth/" xmlns:cbs="http://www.somecompany.com/CBS_GetUpgradeEligibility/" xmlns:esb="http://www.somecompany.com/esbTypes/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.somecompany.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:import namespace="http://www.somecompany.com/esbTypes/" schemaLocation="http://127.0.0.1:5000/CBS_GetUpgradeEligibility?SCHEMA%2FVodacom+Services%2FInfrastructure+Services%2FSchemas%2FXSD_ESBTypes"></xs:import>
        <xs:simpleType name="DESTINATION_MSISDN">
            <xs:restriction base="xs:string">
                <xs:maxLength value="11"></xs:maxLength>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="STRING_13">
            <xs:restriction base="xs:string">
                <xs:maxLength value="13"></xs:maxLength>
            </xs:restriction>
        </xs:simpleType>
        <xs:simpleType name="STRING_20">
            <xs:restriction base="xs:string">
                <xs:maxLength value="20"></xs:maxLength>
            </xs:restriction>
        </xs:simpleType>
        <xs:complexType name="UPGRADE_TYPE_DETAILS">
            <xs:sequence>
                <xs:element maxOccurs="1" minOccurs="1" name="isber" type="cbs:STRING_13"></xs:element>
                <xs:element maxOccurs="1" minOccurs="1" name="isreward" type="cbs:STRING_13"></xs:element>
                <xs:element maxOccurs="1" minOccurs="1" name="code" type="cbs:STRING_20"></xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:complexType name="QUALIFIES_FOR_UPGRADE_DETAILS">
            <xs:sequence>
                <xs:element maxOccurs="1" minOccurs="1" name="isaveragespentmet" type="cbs:STRING_13"></xs:element>
                <xs:element maxOccurs="1" minOccurs="1" name="is7daypremature" type="cbs:STRING_13"></xs:element>
                <xs:element maxOccurs="1" minOccurs="1" name="upgradepossible" type="cbs:STRING_13"></xs:element>
                <xs:element maxOccurs="1" minOccurs="1" name="upgradeduedate" type="cbs:STRING_13"></xs:element>
                <xs:element maxOccurs="1" minOccurs="0" name="UpgradeType" type="cbs:UPGRADE_TYPE_DETAILS"></xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:element name="GetUpgradeEligibilityRequest">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="TSORequest" type="cbs:getUpgradeEligibilityRequestElement"></xs:element>
                </xs:sequence>
            </xs:complexType></xs:element>
        <xs:element name="GetUpgradeEligibilityResponse">
            <xs:complexType>
                <xs:sequence>
                    <xs:element maxOccurs="1" minOccurs="1" name="TSOID" type="esb:TSOID"></xs:element>
                    <xs:element name="TSOResponse" type="cbs:getUpgradeEligibilityResponseElement"></xs:element>
                    <xs:element maxOccurs="1" minOccurs="1" name="TSOResult" type="esb:TSOResult"></xs:element>
                </xs:sequence>
            </xs:complexType></xs:element>
        <xs:complexType name="getUpgradeEligibilityRequestElement">
            <xs:sequence>
                <xs:element maxOccurs="1" minOccurs="1" name="MSISDN" type="cbs:DESTINATION_MSISDN"></xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:complexType name="getUpgradeEligibilityResponseElement">
            <xs:sequence>
                <xs:element maxOccurs="1" minOccurs="1" name="MSISDN" type="cbs:DESTINATION_MSISDN"></xs:element>
                <xs:element maxOccurs="1" minOccurs="1" name="QualifiesForUpgrade" type="cbs:QUALIFIES_FOR_UPGRADE_DETAILS"></xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:schema>