472,342 Members | 1,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

[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_namespace" to "new_namespace".

To achive this goal i've wrote this document:

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

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

<xsl:template match = "/">
<xsl:element name = "ROOT">
<xsl:attribute name = "xmlns:NAME">new_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 4143
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:stylesheet
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:NAME" >
<xsl:apply-templates />
</xsl:template>

<xsl:template match="ROOT" >
<xsl:element name="ROOT">
<xsl:attribute name="xmlns:NAME">
<xsl:text>new_namespace</xsl:text>
</xsl:attribute>
<xsl:apply-templates />
</xsl:element>
</xsl:template>

<xsl:template match="NAME:element" >
<xsl:element name="NAME:element">
<xsl:attribute name="xmlns:NAME">
<xsl:text>new_namespace</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:attribute name="xmlns:NAME">


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:stylesheet 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.google. 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:stylesheet 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:attribute name="xmlns:NAME">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:subElement attr2="yyy">abcdefghi</NAME:subElement>
</NAME:element>
<NAME:element attr1="xxx" >
<NAME:subElement attr2="yyy">abcdefghi</NAME:subElement>
</NAME:element>
</ROOT>

The output will be the following
<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT xmlns:NAME="http://example.org/new">
<NAME:element attr1="xxx">
<NAME:subElement attr2="yyy">abcdefghi</NAME:subElement>
</NAME:element>
<NAME:element attr1="xxx">
<NAME:subElement attr2="yyy">abcdefghi</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
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...
4
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...
3
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...
3
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...
4
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...
8
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...
4
by: jjouett | last post by:
I have the following input XML: <?xml version="1.0"?> <ordersubmit xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
0
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...
2
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...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.