Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 25th, 2009, 12:56 AM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need to convert an existing namespace and add new namespace to the SOAP xml

Hi all,
I am new to XSLT. I need to convert the below xml to my required one with proper namespaces. here in some element I have to add a namespace and for some element I have to modify the name space. Can somebody help me in this.\

Existing xml

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Body>
<Retriev xmlns="http://www.sample.comv002">
<osaReq> <osa:providerService xmlns:osa="http://www.sample.comv001">
<osa:name xmlns:osa="

Last edited by Prabeen; April 25th, 2009 at 01:05 AM. Reason: NO space
Reply With Quote
  #2 (permalink)  
Old April 25th, 2009, 02:12 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Please post the input xml and the needed output xml. Then we shall try.
__________________
Rummy
Reply With Quote
  #3 (permalink)  
Old April 25th, 2009, 02:33 PM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not able to paste the xml completely its getting cut


<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Body>
<Retriev xmlns="http://www.sample.comv002">
<osaReq xmlns="http://holders.praBeen.app.esb.bac.com">
<osa:providerService xmlns:osa="http://complextypes.app.esb.bac.com">
<osa:name xmlns:osa="
Reply With Quote
  #4 (permalink)  
Old April 25th, 2009, 02:40 PM
Friend of Wrox
Points: 6,525, Level: 34
Points: 6,525, Level: 34 Points: 6,525, Level: 34 Points: 6,525, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,221
Thanks: 0
Thanked 238 Times in 237 Posts
Default

If you want to post code sample then make use of the forum features to wrap them into
Code:
[ code ]<root><foo>foobar</foo></root>[ /code ]
(without the spaces between the square brackets and the word 'code' respectively '/code']).
Then post the input you have and the output you want.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #5 (permalink)  
Old April 25th, 2009, 03:24 PM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Martin. Pls find my existing xml and required xml below
Existing xml
Code:
<?xmlversion="1.0"encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Body>
<Retriev 
xmlns="http://www.company.com/xmlschema/resource/metadata/abc/api/v002">
<osaReq>
<osa:providerService 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">
<osa:name 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">Retriev</osa:name>
<osa:operation 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">Retriev</osa:operation>
<osa:version
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">1</osa:version>
</osa:providerService>
<osa:component 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">FFF</osa:component>
<osa:channel 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">PPP</osa:channel>
<osa:requestorService 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">
<osa:name 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">Acct</osa:name>
<osa:operation 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">retSche</osa:operation>
<osa:version
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">1</osa:version>
</osa:requestorService>
<osa:traceId 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">EF54DF6A4CCE-58365984</osa:traceId>
<osa:userId 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">YYY</osa:userId>
<osa:userIdType 
xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001">XXX</osa:userIdType>
</osaReq>
<smControlDetail>
<complex:startTransaction 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002"></complex:startTransaction>
<complex:maxTransaction 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002"></complex:maxTransaction>
<complex:fromDate 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002">2009-02-09</complex:fromDate>
<complex:toDate 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002">2009-04-10</complex:toDate>
</smControlDetail>
<accountIdentifier>
<complex:acct 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002">1234</complex:acct>
<complex:prod 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002">YYY</complex:prod>
<complex:entity 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002">DDDD</complex:entity>
</accountIdentifier>
<pID>1234</pID>
</Retriev>
</soapenv:Body>
</soapenv:Envelope>

Required XML
Code:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/1999/XMLSchema" 
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Body>
<Retriev 
xmlns="http://www.companyname.com/xmlschema/resource/metadata/abc/api/v002">
<osaReq 
xmlns="http://holders.complextypes.app.esb.bac.com">
<osa:providerService 
xmlns:osa="http://complextypes.app.esb.bac.com">
<osa:name 
xmlns:osa="http://complextypes.app.esb.bac.com">Retriev</osa:name>
<osa:operation 
xmlns:osa="http://complextypes.app.esb.bac.com">Retriev</osa:operation>
<osa:version 
xmlns:osa="http://complextypes.app.esb.bac.com">1</osa:version>
</osa:providerService>
<osa:component 
xmlns:osa="http://complextypes.app.esb.bac.com">FFF</osa:component>
<osa:channel 
xmlns:osa="http://complextypes.app.esb.bac.com">PPP</osa:channel>
<osa:requestorService 
xmlns:osa="http://complextypes.app.esb.bac.com">
<osa:name 
xmlns:osa="http://complextypes.app.esb.bac.com">Acct</osa:name>
<osa:operation 
xmlns:osa="http://complextypes.app.esb.bac.com">retSche</osa:operation>
<osa:version 
xmlns:osa="http://complextypes.app.esb.bac.com">1</osa:version>
</osa:requestorService>
<osa:traceId 
xmlns:osa="http://complextypes.app.esb.bac.com">22C772E6E34F-13623906</osa:traceId>
<osa:userId 
xmlns:osa="http://complextypes.app.esb.bac.com">YYY</osa:userId>
<osa:userIdType 
xmlns:osa="http://complextypes.app.esb.bac.com">XXXX</osa:userIdType>
</osaReq>
<smControlDetail 
xmlns="http://holders.complextypes.app.esb.bac.com">
<complex:startTransaction 
xmlns:complex="http://complextypes.app.esb.bac.com"></complex:startTransaction>
<complex:maxTransaction 
xmlns:complex="http://complextypes.app.esb.bac.com"></complex:maxTransaction>
<complex:fromDate 
xmlns:complex="http://complextypes.app.esb.bac.com">2009-02-07</complex:fromDate>
<complex:toDate 
xmlns:complex="http://complextypes.app.esb.bac.com">2009-04-08</complex:toDate>
</smControlDetail>
<accountIdentifier 
xmlns="http://holders.complextypes.app.esb.bac.com">
<complex:acct 
xmlns:complex="http://complextypes.app.esb.bac.com">1234</complex:acct>
<complex:productCode 
xmlns:complex="http://complextypes.app.esb.bac.com">YYY</complex:productCode>
<complex:entity 
xmlns:complex="http://complextypes.app.esb.bac.com">DDD</complex:entity>
</accountIdentifier>
<pID 
xmlns="http://holders.complextypes.app.esb.bac.com">1234</pID>
</Retriev>
</soapenv:Body>
</soapenv:Envelope>

Last edited by Prabeen; April 27th, 2009 at 02:19 PM.
Reply With Quote
  #6 (permalink)  
Old April 26th, 2009, 08:52 AM
Friend of Wrox
Points: 6,525, Level: 34
Points: 6,525, Level: 34 Points: 6,525, Level: 34 Points: 6,525, Level: 34
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,221
Thanks: 0
Thanked 238 Times in 237 Posts
Default

Here is a sample stylesheet:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mc="http://www.company.com/xmlschema/resource/metadata/abc/api/v002"
  xmlns:osa="http://www.company.com/xmlschema/resource/metadata/osa/infrastructure/v001"
  xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002"
  exclude-result-prefixes="mc osa complex"
  version="1.0">
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="mc:Retriev">
    <xsl:element name="{local-name()}" namespace="http://www.bankofamerica.com/xmlschema/resource/metadata/abc/api/v002">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
  
  <xsl:template match="mc:osaReq | mc:smControlDetail | mc:accountIdentifier | mc:pID">
    <xsl:element name="{local-name()}" namespace="http://holders.complextypes.app.esb.bac.com">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>
  
  <xsl:template match="osa:*">
    <xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="complex:*">
    <xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
      <xsl:apply-templates select="@* | node()"/>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #7 (permalink)  
Old April 26th, 2009, 04:39 PM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi martin, Thanks a lot for you reply. I tested the samle xsl you provided. the namespace doesnot come in the output for the sub element osa:name. can you pls tell me how to do it if there are sub elements inside the osa:name element also. thanks once again.
Reply With Quote
  #8 (permalink)  
Old April 27th, 2009, 05:33 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try this.

Add another template for osa:name.

Code:
<xsl:template match="osa:*">
<xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
<xsl:apply-templates select="@* | node()" mode="osa"/>
</xsl:element>
</xsl:template>

<xsl:template match="osa:*" mode="osa">
<xsl:element name="{name()}">
<xsl:apply-templates select="@* | node()" mode="osa"/>
</xsl:element>
</xsl:template>
__________________
Rummy
Reply With Quote
  #9 (permalink)  
Old April 27th, 2009, 01:59 PM
Authorized User
 
Join Date: Apr 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Martin/mrame,
I tried the below sample but it still is not applying. I have pasted the stylesheet which I tried now.Pls let me know if I have done something wrong.Also I tried one more thing in the stylsheet you gave me it worked but it is giving antoher problem.

The XSL which martin gave me
Code:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:mc="http://www.comanyname.com/xmlschema/resource/metadata/oos/api/v002" 
xmlns:osa="http://www.comanyname.com/xmlschema/resource/metadata/osa/infrastructure/v001" 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002" exclude-result-prefixes="mc osa complex" version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="mc:RetrieveFutureTransactionV001">
<xsl:element name="{local-name()}" namespace="http://www.comanyname.com/xmlschema/resource/prabee/abc/api/v002">
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="mc:osaRequestHeader | mc:smControlDetail | mc:accountIdentifier | mc:partyID">
<xsl:element name="{local-name()}" namespace="http://holders.ppppp.app.esb.bac.com">
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="osa:*" mode="osa">
<xsl:element name="{name()}">
<xsl:apply-templates select="@* | node()" mode="osa"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="osa:*">
<xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="complex:*">
<xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

I have modified this XSL to remove the exclude-result-prefixes="mc osa complex" and replace it with exclude-result-prefixes="mc". I am getting the namespaces for osa:name and all the other sub elements. but for tag
Code:
<Retriev 
xmlns="http://www.company.com/xmlschema/resource/metadata/abc/api/v002">
I am getting the following additional namespaces which I dont want.
Code:
 
<RetrieveFutureTransactionV001 
xmlns:complex="http://www.company.com/xmlschema/resource/metadata/abc/complex/v002" 
xmlns:osa="http://www.comanyname.com/xmlschema/resource/metadata/osa/infrastructure/v001" 
xmlns="http://www.comanyname.com/xmlschema/resource/prabee/abc/api/v002">

Last edited by Prabeen; April 27th, 2009 at 02:34 PM.
Reply With Quote
  #10 (permalink)  
Old April 28th, 2009, 12:49 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Please look into my posting. It is different from what you have modified in your code. You have not corrected your code properly for mode attribute.

Change your below code
Code:
<xsl:template match="osa:*" mode="osa">
<xsl:element name="{name()}">
<xsl:apply-templates select="@* | node()" mode="osa"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="osa:*">
<xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
<xsl:apply-templates select="@* | node()"></xsl:apply-templates>
</xsl:element>
to
Code:
<xsl:template match="osa:*">
<xsl:element name="{name()}" namespace="http://complextypes.app.esb.bac.com">
<xsl:apply-templates select="@* | node()" mode="osa"/>
</xsl:element>
</xsl:template>
 
<xsl:template match="osa:*" mode="osa">
<xsl:element name="{name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
__________________
Rummy
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
namespace issue. xml and xsd jamesdurham XML 5 April 7th, 2009 08:13 PM
Transforming XML From One Namespace to Another mail4kaja XSLT 1 November 10th, 2008 10:14 AM
SOAP envelope namespace not shown anboss XSLT 5 August 25th, 2008 05:43 PM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 08:32 AM
xml namespace and asp werD420 XML 1 August 12th, 2005 02:12 PM



All times are GMT -4. The time now is 09:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.