[xsl] Replacing default namespace

Subject: [xsl] Replacing default namespace
From: Scott Sauyet <lists@xxxxxxxxxx>
Date: Fri, 29 Jun 2007 13:01:25 -0400
I'm having a little problem transforming one WSDL file into another. I need to do some minor manipulation of a WSDL generated by one tool before I can process it with another. One of the main things I need to do is change the xmlns:tns attribute. I was naive and thought I could do it just by declaring a new one in my root tag and then mostly doing the identity transform. I'm sure some experts out there can tell me why that doesn't work, but mostly right now, I'm looking to see how to get it right.

The root <definitions> tag in the original WSDL has

xmlns:tns="http://tempuri.org/";

Now throughout the document, elements that look like these:

    <xs:simpleType name="addrFormat" .../>
    <service name="SessionsService" .../>

get transformed into these:

    <xs:simpleType xmlns:tns="http://tempuri.org/"; name="addrFormat">
    <service xmlns:tns="http://tempuri.org/"; name="SessionsService">

There must be some simple way to control this.

Any suggestions? The entire (short) WSDL is below.

Thanks,

-- Scott

============================================================

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
    xmlns:tns="MyNewNamespace"
    xmlns:n1="http://schemas.xmlsoap.org/wsdl/";
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>

<xsl:param name="bindings" select="'Service'"/>

<xsl:template match="/wsdl:definitions">
<definitions
    targetNamespace="MyNewNamespace"
    xmlns="http://schemas.xmlsoap.org/wsdl/";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:tns="@Service@"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/";
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/";
    xmlns:ro="urn:Databox"
>
    <xsl:apply-templates/>
</definitions>
</xsl:template>

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

<xsl:template match="xs:schema">
    <xs:schema targetNamespace="urn:Databox" xmlns="urn:Databox">
        <xsl:text>
         </xsl:text>
        <xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/";
            schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
    <xsl:apply-templates/>
    </xs:schema>
</xsl:template>

<xsl:template match="node() | @*">
     <xsl:copy>
          <xsl:apply-templates select="node() | @*"/>
     </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Current Thread