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 28th, 2018, 02:22 PM
Authorized User
Points: 110, Level: 2
Points: 110, Level: 2 Points: 110, Level: 2 Points: 110, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2018
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Default Need to change target XML namespace

Source XML:
========

<FundXML>
<FundFacts>
<KeyFacts>
<Registration>
<Country>AE</Country>
</Registration>
<Registration>
<Country>AE</Country>
</Registration>
<Registration>
<Country>AT</Country>
</Registration>
<Registration>
<Country>AT</Country>
</Registration>
<Registration>
<Country>TW</Country>
</Registration>
<Registration>
<Country>ZA</Country>
</Registration>
</KeyFacts>
</FundFacts>
</FundXML>


Target XML:
========

<FundXML xsi:schemaLocation="www.fund1.com www.fund2.com"
xmlns="www.fund1.org/Schema" xmlns:xsi="http://www.fund2.org/Schema-Instance" >
<FundFacts>
<KeyFacts>
<Registration>
<Country>AE</Country>
</Registration>
<Registration>
<Country>AE</Country>
</Registration>
<Registration>
<Country>AT</Country>
</Registration>
<Registration>
<Country>AT</Country>
</Registration>
<Registration>
<Country>TW</Country>
</Registration>
<Registration>
<Country>ZA</Country>
</Registration>
</KeyFacts>
</FundFacts>
</FundXML>

Code
=======

Need to add
<FundXML xsi:schemaLocation="www.fund1.com www.fund2.com"
xmlns="www.fund1.org/Schema" xmlns:xsi="http://www.fund2.org/Schema-Instance" >

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

<xsl:template match="*[namespace-uri()='']">
<xsl:element name="{local-name()}" namespace="www.fund1.org/Schema">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

Last edited by virgosaggi; April 28th, 2018 at 02:43 PM.
Reply With Quote
  #2 (permalink)  
Old April 28th, 2018, 05:12 PM
Authorized User
Points: 110, Level: 2
Points: 110, Level: 2 Points: 110, Level: 2 Points: 110, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2018
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Default

The following code is not working


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>


<xsl:template match="/FundXML">
<FundXML xsi:schemaLocation="www.fund1.com www.fund2.com"
xmlns="www.fund1.org/Schema"
xmlns:xsi="http://www.fund2.org/Schema-Instance">
<xsl:apply-templates select="@*|node()"/>
</FundXML>
</xsl:template>

<xsl:template match="*[namespace-uri()='']">
<xsl:element name="{local-name()}" namespace="www.fund1.org/Schema">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Any help would be much appreciated
Reply With Quote
  #3 (permalink)  
Old April 29th, 2018, 04:41 AM
Friend of Wrox
Points: 6,612, Level: 34
Points: 6,612, Level: 34 Points: 6,612, Level: 34 Points: 6,612, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,234
Thanks: 0
Thanked 242 Times in 241 Posts
Default

I would use

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.fund1.org"
	version="2.0">

  <xsl:template match="/FundXML">
      <FundXML xsi:schemaLocation="http://www.fund1.org http://www.fund2.com/schema.xsd" 
           xmlns:xsi="http://www.fund2.org/Schema-Instance">
          <xsl:apply-templates/>
      </FundXML>
  </xsl:template>
  
  <xsl:template match="*">
      <xsl:element name="{local-name()}">
          <xsl:apply-templates select="@* | node()"/>
      </xsl:element>
  </xsl:template>
  
</xsl:stylesheet>
Online sample showing the result at https://xsltfiddle.liberty-development.net/gWmuiJ3, you might need to adjust the namespace URI and the schema URI.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
virgosaggi (April 29th, 2018)
  #4 (permalink)  
Old April 29th, 2018, 10:09 AM
Authorized User
Points: 110, Level: 2
Points: 110, Level: 2 Points: 110, Level: 2 Points: 110, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2018
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Martin Honnen View Post
I would use

Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.fund1.org"
	version="2.0">

  <xsl:template match="/FundXML">
      <FundXML xsi:schemaLocation="http://www.fund1.org http://www.fund2.com/schema.xsd" 
           xmlns:xsi="http://www.fund2.org/Schema-Instance">
          <xsl:apply-templates/>
      </FundXML>
  </xsl:template>
  
  <xsl:template match="*">
      <xsl:element name="{local-name()}">
          <xsl:apply-templates select="@* | node()"/>
      </xsl:element>
  </xsl:template>
  
</xsl:stylesheet>
Online sample showing the result at https://xsltfiddle.liberty-development.net/gWmuiJ3, you might need to adjust the namespace URI and the schema URI.
Thanks Martin for your reply
I managed to sort it late last night forgot to update the thread with the code, but thnk you very much for your quick update
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
Changing namespace url from source xml in target xml Hexxor XSLT 0 January 25th, 2012 02:44 AM
How to include namespace in the target xml in a simple way? spring2009 XSLT 1 September 9th, 2010 10:46 AM
error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'Syste shailesh_kumar C# 2008 aka C# 3.0 8 August 20th, 2009 03:11 AM
Need to convert an existing namespace and add new namespace to the SOAP xml Prabeen XSLT 10 April 28th, 2009 10:18 AM
VBScript to change target of Iframe dartcoach BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 May 9th, 2008 11:45 AM



All times are GMT -4. The time now is 06:20 AM.


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