473,372 Members | 828 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,372 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 3898
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.