XSLT remove 'EncodingStyle'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Evolution445
    New Member
    • Jul 2007
    • 63

    XSLT remove 'EncodingStyle'

    Hello,


    I'm currently working with XSLT, although rather simplistic. I'm struggling trying to remove the encodingstyle property from a SOAP XML envelope using XSLT scripts.

    This is the XML I'm working with, a simple testing envelope:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <soapenv:envelope xmlns:urn="schemas-microsoft-com:office:spreadsheet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:header/>
    <soapenv:body>
    <urn:helloworld soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
    <clientdata xsi:type="urn:clientdata">
    <username xsi:type="xsd:string">test</username>
    <password xsi:type="xsd:string">test</password>
    </clientdata>
    </urn:helloworld>
    </soapenv:body>
    </soapenv:envelope>
    This is my desired output:

    Code:
    <envelope>
    <body>
    <helloworld>
    <clientdata>
    <username>test</username>
    <password>test</password>
    </clientdata>
    </helloworld>
    </body>
    </envelope>
    In short, stripping all SOAP elements (and the header) and 'converting' this to plain XML for further processing via more XSLT scripts.

    This is the current script Im working with:

    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsi">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
    <xsl:template match="/|comment()|processing-instruction()">
     <xsl:copy>
      <xsl:apply-templates/>
     </xsl:copy>
    </xsl:template>
    <xsl:template match="*">
     <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
     </xsl:element>
    </xsl:template>
    <xsl:template match="@xsi:type"/>
    <xsl:template match="@encodingstyle"/>
    </xsl:stylesheet>
    The output Im currently receiving is:

    Code:
    <envelope>
    <header />
    <body>
    <helloworld>http://schemas.xmlsoap.org/soap/encoding/
    <clientdata>
    <username>test</username>
    <password>test</password>
    </clientdata>
    </helloworld>
    </body>
    </envelope>
    So in other words, I nearly managed to clear the encodingstyle property but the URL is still left there.

    I'm thinking the quickest and easiest way to get rid of the header is by using something along the lines of copy-of select="soap:bo dy/*" so the only remaining thing is infact the body (which is perfectly fine too). However, I just cannot figure out how to rid the encodingstyle property entirely. Something such as " <xsl:template match="@encodin gstyle"/> " does not appear to have any effect whatsoever.

    Does anyone have any hits/suggestions, or perhaps an alteration to my script?


    Thanks in advance.
    Last edited by Evolution445; Jan 8 '13, 10:16 AM. Reason: Spelling
  • Evolution445
    New Member
    • Jul 2007
    • 63

    #2
    I have managed to get just the body after many alterations to the initial XSLT script:

    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="xsi">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
    <xsl:template match="*">
     <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@* | node()"/>
     </xsl:element>
    </xsl:template>
    <xsl:template match="@xsi:type"/>
    </xsl:stylesheet>
    And then through a 2nd script to get only the body:

    Code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
    <xsl:template match="/">
     <xsl:copy-of select="/envelope/body/*"/>
    </xsl:template>
    </xsl:stylesheet>
    The current output is:

    Code:
    <helloworld>http://schemas.xmlsoap.org/soap/encoding/
       <clientdata>
       <username>test</username>
       <password>test</password>
      </clientdata>
     </helloworld>
    How can I get rid of the encodingstyle attribute completely? Also, is there any quick way in XSLT to trim spaces in front of elements? I have attempted strip spaces but this puts everything on one single line.

    Comment

    • Evolution445
      New Member
      • Jul 2007
      • 63

      #3
      It appears adding namespace:

      xmlns:soapenv=" http://schemas.xmlsoap .org/soap/envelope/"

      And adding this line:

      <xsl:template match="@soapenv :encodingstyle"/>

      Seems to have solved my issue.

      Comment

      Working...