468,470 Members | 1,968 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,470 developers. It's quick & easy.

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:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <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/">
  3. <soapenv:header/>
  4. <soapenv:body>
  5. <urn:helloworld soapenv:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/">
  6. <clientdata xsi:type="urn:clientdata">
  7. <username xsi:type="xsd:string">test</username>
  8. <password xsi:type="xsd:string">test</password>
  9. </clientdata>
  10. </urn:helloworld>
  11. </soapenv:body>
  12. </soapenv:envelope>
  13.  
This is my desired output:

Expand|Select|Wrap|Line Numbers
  1. <envelope>
  2. <body>
  3. <helloworld>
  4. <clientdata>
  5. <username>test</username>
  6. <password>test</password>
  7. </clientdata>
  8. </helloworld>
  9. </body>
  10. </envelope>
  11.  
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:

Expand|Select|Wrap|Line Numbers
  1. <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">
  2. <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
  3. <xsl:template match="/|comment()|processing-instruction()">
  4.  <xsl:copy>
  5.   <xsl:apply-templates/>
  6.  </xsl:copy>
  7. </xsl:template>
  8. <xsl:template match="*">
  9.  <xsl:element name="{local-name()}">
  10.   <xsl:apply-templates select="@*|node()"/>
  11.  </xsl:element>
  12. </xsl:template>
  13. <xsl:template match="@xsi:type"/>
  14. <xsl:template match="@encodingstyle"/>
  15. </xsl:stylesheet>
  16.  
The output Im currently receiving is:

Expand|Select|Wrap|Line Numbers
  1. <envelope>
  2. <header />
  3. <body>
  4. <helloworld>http://schemas.xmlsoap.org/soap/encoding/
  5. <clientdata>
  6. <username>test</username>
  7. <password>test</password>
  8. </clientdata>
  9. </helloworld>
  10. </body>
  11. </envelope>
  12.  
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:body/*" 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="@encodingstyle"/> " does not appear to have any effect whatsoever.

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


Thanks in advance.
Jan 8 '13 #1

✓ answered by Evolution445

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.

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

Expand|Select|Wrap|Line Numbers
  1. <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">
  2. <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
  3. <xsl:template match="*">
  4.  <xsl:element name="{local-name()}">
  5.   <xsl:apply-templates select="@* | node()"/>
  6.  </xsl:element>
  7. </xsl:template>
  8. <xsl:template match="@xsi:type"/>
  9. </xsl:stylesheet>
  10.  
And then through a 2nd script to get only the body:

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
  3. <xsl:template match="/">
  4.  <xsl:copy-of select="/envelope/body/*"/>
  5. </xsl:template>
  6. </xsl:stylesheet>
  7.  
The current output is:

Expand|Select|Wrap|Line Numbers
  1. <helloworld>http://schemas.xmlsoap.org/soap/encoding/
  2.    <clientdata>
  3.    <username>test</username>
  4.    <password>test</password>
  5.   </clientdata>
  6.  </helloworld>
  7.  
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.
Jan 8 '13 #2
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.
Jan 9 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Trygve | last post: by
1 post views Thread by mountain1228 | last post: by
2 posts views Thread by Claudio Jolowicz | last post: by
4 posts views Thread by FrankIsHere | last post: by
6 posts views Thread by kluge.wolfram | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.