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 November 12th, 2007, 02:17 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default Changing namespace on copy

Hi all!

What's the most effective way of changing the namespace of a node when copying it? Here's a simple example:


<ns1:root xmlns:ns1="http://www.someUrl.com/ns1">
  <ns1:element>element to be imported</ns1:element>
</ns1:root>


<abc:result xmlns:abc="http://www.myUrl.org/elements">
  <abc:element>element to be imported</abc:element>
</abc:result>


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://www.someUrl.com/ns1" xmlns:abc="http://www.myUrl.org/elements" exclude-result-prefixes="ns1">
 <xsl:template match="/">
  <abc:result>

   <xsl:copy-of select="//ns1:element[1]"/>
  </abc:result>
 </xsl:template>
</xsl:stylesheet>

This example is quite simple, but in my case, the element to be copied is several levels deep, all of it's descendants are in the same source namespace and have to be converted to the result namespace.

Thanks,

Rushman

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
__________________
Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old November 12th, 2007, 02:29 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:template match="node()">
   <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
<xsl:template mach="@*">
   <xsl:atribute name="{local-name()}"/>
</xsl:attribute>


You can then either set the default namspace on the stylesheet element (xsmlns="http://whatever"), add the namespace attribute to the xsl:element and xsl:attribute instructons, or even add a custom declared prefix to the name attribute (name="ns0:{local-name()}")

/- Sam Judson : Wrox Technical Editor -/
 
Old November 12th, 2007, 02:35 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Thanks Sam for your quick reply. I guess I'm gonna use the name="abc:{local-name()}" approach.

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
About Namespace cfanllm C# 2005 5 April 13th, 2007 08:15 AM
Namespace copy problem francislang XSLT 3 February 20th, 2006 01:07 PM
copy-of xsi namespace chris_strub XSLT 2 October 2nd, 2004 10:32 PM
Namespace flute Pro VB.NET 2002/2003 2 October 21st, 2003 09:15 AM
namespace shortynelson C# 2 September 9th, 2003 03:14 AM





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