473,574 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[XSL] Changing namespace definition

Hi,

i have one problem with an xsl trasformation (I'm using Xalan)

The source XML document is the following:

<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<ROOT xmlns:NAME='old _namespace'>
<NAME:element>. ..</NAME:element>
<NAME:element>. ..</NAME:element>
</ROOT>

What i want is to change the uri of the namespace from
"old_namesp ace" to "new_namespace" .

To achive this goal i've wrote this document:

<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:styleshe et
version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:NAME = "old_namespace" >

<xsl:template match = "/">
<xsl:element name = "ROOT">
<xsl:attribut e name = "xmlns:NAME">ne w_namespace</xsl:attribute>
<xsl:copy-of select="/ROOT/NAME:element" />
</xsl:element>
</xsl:template>

</xsl:styleshee>

And the result of the transformation is:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:NAME="new _namespace">
<NAME:element xmlns:NAME="old _namespace">... </NAME:element>
<NAME:element xmlns:NAME="old _namespace">... </NAME:element>
</ROOT>

The namespace definition in the root element is changed
but the processor have put the old namespace definition
in every child of the root.

The result that i expected is

<?xml version="1.0" encoding="UTF-8"?>
<ROOT xmlns:NAME="new _namespace">
<NAME:element>. ..</NAME:element>
<NAME:element>. ..</NAME:element>
</ROOT>

I hope that the explanation of the problem was clear.

Thanks
Jul 20 '05 #1
6 4229
In article <f5************ **************@ posting.google. com>,
insane79 <rr*****@libero .it> wrote:
What i want is to change the uri of the namespace from
"old_namespace " to "new_namespace" .


You can't just change the declaration on the top-level element: the
elements will still be in the old namespace and XSLT will generate
declarations to make sure they are.

You need a template that copies each element by creating a new element
with the same local name but the new namespace name. You can modify
the usual identity transform to do this.

-- Richard
Jul 20 '05 #2
ri*****@cogsci. ed.ac.uk (Richard Tobin) wrote in message news:<c8******* ****@pc-news.cogsci.ed. ac.uk>...
You need a template that copies each element by creating a new element
with the same local name but the new namespace name. You can modify
the usual identity transform to do this.
I'm not sure if i understand in the right way, honwever
i've wrote the following document

<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:styleshe et
version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
xmlns:NAME = "old_namespace" >

<xsl:output
method="xml"
version="1.0"
encoding="ISO-8859-1" />

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

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

<xsl:template match="@xmlns:N AME" >
<xsl:apply-templates />
</xsl:template>

<xsl:template match="ROOT" >
<xsl:element name="ROOT">
<xsl:attribut e name="xmlns:NAM E">
<xsl:text>new_n amespace</xsl:text>
</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="NAME:ele ment" >
<xsl:element name="NAME:elem ent">
<xsl:attribut e name="xmlns:NAM E">
<xsl:text>new_n amespace</xsl:text>
</xsl:attribute>
<xsl:copy>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

But the resutlt is the same of before: the old namespace
declaration is put into every child of ROOT.

Where i'm doing the wrong thing?
-- Richard


Bye
Roberto
Jul 20 '05 #3
rr*****@libero. it (insane79) writes:
ri*****@cogsci. ed.ac.uk (Richard Tobin) wrote in message news:<c8******* ****@pc-news.cogsci.ed. ac.uk>...
You need a template that copies each element by creating a new element
with the same local name but the new namespace name. You can modify
the usual identity transform to do this.

<snip/>
But the resutlt is the same of before: the old namespace
declaration is put into every child of ROOT.

Where i'm doing the wrong thing?


See my reply earlier today to Chris Bedford in the thread "how to get
the identity transformation to stop outputting extra 'xmlns:' attrib
?" in this group. It tells you what you need to know.

Ben

--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #4
In article <f5************ **************@ posting.google. com>,
insane79 <rr*****@libero .it> wrote:
<xsl:attribut e name="xmlns:NAM E">


You're still trying to change the namespace declarations (which you
can't: they're not part of the XPath data model), instead of the
elements themselves. You need something like this:

<xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:old="http ://example.org/old">

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

<xsl:template match="old:*">
<xsl:element name="{local-name()}" namespace="http ://example.org/new">
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

-- Richard
Jul 20 '05 #5
> See my reply earlier today to Chris Bedford in the thread "how to get
the identity transformation to stop outputting extra 'xmlns:' attrib
?" in this group. It tells you what you need to know.
Thanks for the hint, i've tried both your solution and the one from Chris
but without any good result.

I can change the namespace in the root node but the old namespace is still
applied to every child.
Ben


Bye
Roberto
Jul 20 '05 #6
rr*****@libero. it (insane79) wrote in message news:<f5******* *************** ****@posting.go ogle.com>...
Hi,
i have one problem with an xsl trasformation (I'm using Xalan)


[CUT]

I've solved the problem (with your help) and i post thee solution
in the hope that can be usefull for somebody.

The xslt document is the following:

<?xml version="1.0" encoding="iso-8859-1"?>

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:NAME="old _namespace">

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

<xsl:template match="NAME:*">
<xsl:element name="{name()}" >
<xsl:apply-templates select="node()| @*"/>
</xsl:element>
</xsl:template>

<xsl:template match="ROOT">
<xsl:element name="ROOT">
<xsl:attribut e name="xmlns:NAM E">http://example.org/new</xsl:attribute>
<xsl:apply-templates select="node()| @*"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

If you put in input an XML like this:

<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<ROOT xmlns:NAME='old _namespace'>
<NAME:element attr1="xxx" >
<NAME:subElemen t attr2="yyy">abc defghi</NAME:subElement >
</NAME:element>
<NAME:element attr1="xxx" >
<NAME:subElemen t attr2="yyy">abc defghi</NAME:subElement >
</NAME:element>
</ROOT>

The output will be the following
<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT xmlns:NAME="htt p://example.org/new">
<NAME:element attr1="xxx">
<NAME:subElemen t attr2="yyy">abc defghi</NAME:subElement >
</NAME:element>
<NAME:element attr1="xxx">
<NAME:subElemen t attr2="yyy">abc defghi</NAME:subElement >
</NAME:element>
</ROOT>

So only the namespace declaration in the root element is changed

Many for your help

Bye
Roberto
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2265
by: chris | last post by:
Hi, After going back through the XSL tutorials and the help here I have largely solved the problem of merging two XHTML files, but one small detail remains... The parser outputs <html xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
4
2293
by: Jean-Christophe Michel | last post by:
Hi, In a complex merging of two (non ordered) xml files i need to keep track of the elements of the second tree that were already merged with first tree, to copy only unused elements at the end. I tried two solutions: * first is to 'substract' the used element from existing tree
3
1910
by: william_hulse | last post by:
The general process i am currently working on is this: STEP 1 xml doc1 is transformed using stylesheet1 to produce xml doc2 - xml doc1 has a namespace declaration as follows... <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> <?xml-stylesheet type="text/xsl"...
3
1396
by: schaf | last post by:
Hello NG! I would like to transform a XML-File into an new XML-File with additional information. That's no problem, but my source XML-File has a root element with a xmlns definition. Like this <Header xmlns="http://www.myHeader.ch/TestHeadrer"> If i would like to copy this tag, with the following xsl-code, nothing is working:
4
1360
by: n.phelge | last post by:
I'm trying to validate XML which doesn't include a namespace, so I've written a schema and I'm attempting to add a namespace to the original XML using XSLT. The original XML looks like this: <orderlist> <order> <header> <ordernum>1313</ordernum> </header> </order>
8
5263
by: Markus Wildgruber | last post by:
Hi! We want to use XSL-FO in the reporting of our application. Before making the decision we have some questions on that topic: Does anyone have experience with XSL-FO in the .NET environment? Is that a useful technique for professional reporting? Is it technically mature? Does anyone know of a control (WinForms/WebForms) that we can...
4
1574
by: jjouett | last post by:
I have the following input XML: <?xml version="1.0"?> <ordersubmit xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.company.com/webservices/ordersubmit"> <order> <header> <ordername>TestOrder</ordername>
0
997
by: Nick | last post by:
I am creating a website for a client and I am using XSL for my email templates and I have that parses the templates and creates an email. I have a custom class called EmailAddress which has one parameter of type string that is named email. In this class I have some private verification functions for the address. Another class I have is...
2
1458
by: shapper | last post by:
Hello, I created a XSL file to convert a XML file to another XML. I am running this in Asp.Net but this is not working. ----- ORIGINAL XML ----- <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/ASPNet/SiteMap-File-1.0" >
0
7808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7732
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8243
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7822
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5302
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.