473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 3902
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

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

Similar topics

4
by: Trygve | last post by:
I'm trying to convert a XML-document using XSLT. Depending on the source file (the XML-document) the conversion is either correct or incorrect. If the first tag in the document contains an non...
1
by: Johannes Koch | last post by:
How to remove multiple elements with the same child element content? E.g. input: <root> <foo> <bar>ABC</bar> </foo> <foo> <bar>DEF</bar> </foo>
1
by: mountain1228 | last post by:
Hello, I apoligize in advance if this post is off-topic in this group. I have been converting xml to html with an xslt stylesheet using the program xslt-parser that comes with RH 7.3. The...
2
by: Claudio Jolowicz | last post by:
How can XSLT stylesheets be used to edit, remove and add nodes specified by their position in the document tree? The XML document stores development tasks in a hierarchical way, i.e. tasks can...
0
by: johnsocs | last post by:
All I'm trying to write an xml schema for the following xml from the google web service api. In the schema I'm not sure how to describe the soapenv:encodingStyle attribute. Thanks. <?xml...
4
by: FrankIsHere | last post by:
Hi! I cannot figure out how to remove XHTML tags from an XML source file using XSLT. Here's what I have: source XML file: <?xml version='1.0'?> <Offer ID="S0173"...
0
by: Himmat Dhange | last post by:
Hi, I am using .Net Framework 1.0 for Web service development. I use XMLValidatingReader for SOAP request validations. If request contains "encodingStyle" attribute on SOAP Envelope element...
3
by: M Borkan | last post by:
Can anyone tell me how to access the encodingStyle in a client from a SoapExtension? In particular, I'd like to know the style in SoapClientMessage in the SoapMessageStage.BeforeSerialize. I'm...
12
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform...
6
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.