Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2018, 02:22 PM
Authorized User
 
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..
 
Old April 28th, 2018, 05:12 PM
Authorized User
 
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
 
Old April 29th, 2018, 04:41 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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
The Following User Says Thank You to Martin Honnen For This Useful Post:
virgosaggi (April 29th, 2018)
 
Old April 29th, 2018, 10:09 AM
Authorized User
 
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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing namespace url from source xml in target xml Hexxor XSLT 0 January 25th, 2012 03: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.