<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:soapenv11="http://schemas.xmlsoap.org/soap/envelope/"
                xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/">

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

<xsl:template match="@xsi:type[.='soapenc:Array']"/>

<xsl:template match="@soapenc11:arrayType">
  <xsl:attribute name="itemType" namespace="http://www.w3.org/2003/05/soap-encoding">

    <!-- TODO: only type[5] cases are handled, support for
         type[,,,][5,6,7] will require regexps -->

    <xsl:value-of select="substring-before(.,'[')"/>
  </xsl:attribute>
  <xsl:attribute name="arraySize" namespace="http://www.w3.org/2003/05/soap-encoding">
    <xsl:value-of select="substring-before(substring-after(.,'['),']')"/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@href">
  <xsl:attribute name="ref" namespace="http://www.w3.org/2003/05/soap-encoding">
    <xsl:value-of select="substring(.,2)"/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@id">
  <xsl:attribute name="id" namespace="http://www.w3.org/2003/05/soap-encoding">
  <!--  <xsl:apply-templates/> -->
     <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@soapenc11:root"/>

<xsl:template match="soapenv11:*">
  <xsl:element name="{local-name()}" namespace="http://www.w3.org/2003/05/soap-envelope">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@soapenv11:*">
  <xsl:attribute name="{local-name()}" namespace="http://www.w3.org/2003/05/soap-envelope">
    <xsl:apply-templates/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="@soapenv11:encodingStyle">
  <xsl:attribute name="encodingStyle" namespace="http://www.w3.org/2003/05/soap-encoding">
    <xsl:text>http://www.w3.org/2003/05/soap-encoding</xsl:text>
  </xsl:attribute>
</xsl:template>

</xsl:stylesheet>
